You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Paul Benedict <pa...@yahoo.com> on 2006/08/20 05:48:45 UTC
Struts URL Pattern
Does anyone know how to get the Struts servlet pattern at runtime? I want to get what the servlet is mapped for, like *.do or /do/, etc.
Paul
---------------------------------
Do you Yahoo!?
Next-gen email? Have it all with the all-new Yahoo! Mail Beta.
RE: Struts URL Pattern
Posted by David Friedman <hu...@ix.netcom.com>.
If you are in a time crunch for an answer, you could always load the
resourceAsStream "/WEB-INF/web.xml" with a SAX parser, first findi your
servlet name, and then iterate through the mappings to match the servlet
name so you can obtain the mapping. Personally, I tried to discover the
same thing with Struts about two years ago but never found a way other than
the above method.
Regards,
David
-----Original Message-----
From: Paul Benedict [mailto:paul4christ79@yahoo.com]
Sent: Saturday, August 19, 2006 11:49 PM
To: user@struts.apache.org
Subject: Struts URL Pattern
Does anyone know how to get the Struts servlet pattern at runtime? I want to
get what the servlet is mapped for, like *.do or /do/, etc.
Paul
---------------------------------
Do you Yahoo!?
Next-gen email? Have it all with the all-new Yahoo! Mail Beta.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
RE: Struts URL Pattern
Posted by Paul Benedict <pa...@yahoo.com>.
Awesome find. Thanks David!
David Friedman <hu...@ix.netcom.com> wrote: My bad, what was I thinking? LOL. Try this:
servlet.getServletConfig().getServletContext().getAttribute(Globals.SERVLET_
KEY));
As in this example where I print out an error message:
public class DavidAction extends Action {
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws
Exception {
System.out.println("Hello Paul, the Struts prefix or suffix mapping is: "
+ servlet.getServletConfig().getServletContext().getAttribute(
Globals.SERVLET_KEY));
return (mapping.findFoward("success"));
}
And my logged response was:
> Hello Paul, the Struts prefix or suffix mapping is: *.do
Regards,
David
-----Original Message-----
From: Paul Benedict [mailto:paul4christ79@yahoo.com]
Sent: Saturday, August 19, 2006 11:49 PM
To: user@struts.apache.org
Subject: Struts URL Pattern
Does anyone know how to get the Struts servlet pattern at runtime? I want to
get what the servlet is mapped for, like *.do or /do/, etc.
Paul
---------------------------------
Do you Yahoo!?
Next-gen email? Have it all with the all-new Yahoo! Mail Beta.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
---------------------------------
Stay in the know. Pulse on the new Yahoo.com. Check it out.
RE: Struts URL Pattern
Posted by David Friedman <hu...@ix.netcom.com>.
My bad, what was I thinking? LOL. Try this:
servlet.getServletConfig().getServletContext().getAttribute(Globals.SERVLET_
KEY));
As in this example where I print out an error message:
public class DavidAction extends Action {
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws
Exception {
System.out.println("Hello Paul, the Struts prefix or suffix mapping is: "
+ servlet.getServletConfig().getServletContext().getAttribute(
Globals.SERVLET_KEY));
return (mapping.findFoward("success"));
}
And my logged response was:
> Hello Paul, the Struts prefix or suffix mapping is: *.do
Regards,
David
-----Original Message-----
From: Paul Benedict [mailto:paul4christ79@yahoo.com]
Sent: Saturday, August 19, 2006 11:49 PM
To: user@struts.apache.org
Subject: Struts URL Pattern
Does anyone know how to get the Struts servlet pattern at runtime? I want to
get what the servlet is mapped for, like *.do or /do/, etc.
Paul
---------------------------------
Do you Yahoo!?
Next-gen email? Have it all with the all-new Yahoo! Mail Beta.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org