You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Ov...@posten.se on 2006/12/07 09:32:17 UTC
Struts2: How can I make a Filter redirecting to struts actions
Hi everybody,
I have experimented with a filter that triggers for keywords on the
request URL
and when found it should redirect to a struts action that processes the
keyword.
My dilemma is that I don't want to use:
response.sendRedirect("/some.action");
becoz redirect should be done internally in the servlet container, not
via browser.
I have tested:
request.getRequestDispatcher("/some.action").forward(request, response);
and it don't work. I guess becoz an action mapping is not a servlet, an
JSP page is.
Does anyone have an idea how to solve this? Any input welcome!
One approach could be to inherit:
org.apache.struts2.dispatcher.FilterDispatcher
and override doFilter() method and insert my keyword code. Kinda ugly
thou.
Regardings,
Ove Oldberg, Sweden.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
RE: Struts2: How can I make a Filter redirecting to struts actions - SOLVED!
Posted by Ov...@posten.se.
Hi Dariusz,
Thanks for the input. After some coding and reading in the Struts 2.0.2 sourcecode I got this to work.
In general it seems that Struts2 uses two methods from the request to examine URI (in this order):
- request.getServletPath()
- request.getRequestURI()
The real trick is, as you suggested, to create my own instance of HttpServletRequest and implement set-methods for those two, manipulate the values and pass on the reference to filter.doFilter(req, res). The nice thing is that there is a javax.servlet.http.HttpServletRequestWrapper class that do a base implementation of the request. Extend that and implement setServletPath(String arg0) and setRequestURI(String arg0) methods.
Very nice!
------
Martin Gainty-
Thanks for your input to my question. As you understand of my answer above, a redirect from an JSP page is way to late in the request sequence. The thing with keywords is to implement Wiki functionallity into a normal Struts built website. If a client request http://somesite.com/keyword my filter ask the WikiEngine if it recognizes the keyword. If it does, I modify the request to my template.action instead. I store the Wiki keyword as an request attribute to be picked up and presented by the template. By this I can serve simple easy editable pages in Wiki format and use Struts for more advanced pages. An important goal is to hide the redirect for a web browser so when a user bookmarks a page, the url point to a keyword and not an ugly redirect.
------
Thanks again for the help!
Regards,
Ove Oldberg
> -----Ursprungligt meddelande-----
> Från: Dariusz Wojtas [mailto:dwojtas@gmail.com]
> Skickat: den 7 december 2006 09:39
> Till: Struts Users Mailing List
> Ämne: Re: Struts2: How can I make a Filter redirecting to
> struts actions
>
> Hi,
>
> If your filter is called before the struts filter, then what about
> preparing your own HttpServletRequest instance (some wrapper) and
> passing it deeper into doFilter(..)?
> You could copy all properties of the original request but change the
> URI (or whatever property is responsible for it).
> The next filter/servlet would be fooled by this switch and their
> calculations (ie. finding what action should be executed) would be
> done on data prepared by you.
>
> Best regards
> Dariusz Wojtas, Poland
>
> On 12/7/06, Ove.Oldberg@posten.se <Ov...@posten.se> wrote:
> > Hi everybody,
> > I have experimented with a filter that triggers for keywords on the
> > request URL
> > and when found it should redirect to a struts action that
> processes the
> > keyword.
> >
> > My dilemma is that I don't want to use:
> > response.sendRedirect("/some.action");
> > becoz redirect should be done internally in the servlet
> container, not
> > via browser.
> >
> > I have tested:
> >
> request.getRequestDispatcher("/some.action").forward(request,
> response);
> > and it don't work. I guess becoz an action mapping is not a
> servlet, an
> > JSP page is.
> >
> > Does anyone have an idea how to solve this? Any input welcome!
> >
> > One approach could be to inherit:
> > org.apache.struts2.dispatcher.FilterDispatcher
> > and override doFilter() method and insert my keyword code.
> Kinda ugly
> > thou.
> >
> > Regardings,
> > Ove Oldberg, Sweden.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts2: How can I make a Filter redirecting to struts actions
Posted by Dariusz Wojtas <dw...@gmail.com>.
Hi,
If your filter is called before the struts filter, then what about
preparing your own HttpServletRequest instance (some wrapper) and
passing it deeper into doFilter(..)?
You could copy all properties of the original request but change the
URI (or whatever property is responsible for it).
The next filter/servlet would be fooled by this switch and their
calculations (ie. finding what action should be executed) would be
done on data prepared by you.
Best regards
Dariusz Wojtas, Poland
On 12/7/06, Ove.Oldberg@posten.se <Ov...@posten.se> wrote:
> Hi everybody,
> I have experimented with a filter that triggers for keywords on the
> request URL
> and when found it should redirect to a struts action that processes the
> keyword.
>
> My dilemma is that I don't want to use:
> response.sendRedirect("/some.action");
> becoz redirect should be done internally in the servlet container, not
> via browser.
>
> I have tested:
> request.getRequestDispatcher("/some.action").forward(request, response);
> and it don't work. I guess becoz an action mapping is not a servlet, an
> JSP page is.
>
> Does anyone have an idea how to solve this? Any input welcome!
>
> One approach could be to inherit:
> org.apache.struts2.dispatcher.FilterDispatcher
> and override doFilter() method and insert my keyword code. Kinda ugly
> thou.
>
> Regardings,
> Ove Oldberg, Sweden.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts2: How can I make a Filter redirecting to struts actions
Posted by Martin Gainty <mg...@hotmail.com>.
Ove-
in your jsp
You can hook redirect-action to yout submit button as in
<a:submit name="redirect-action:someAction" value="OK"/>
http://struts.apache.org/WW/actionmapper.html
code
in your Action class execute method
mapping.findForward("someAction")
where struts.xml has
<action name="someAction" class="org.sverige.someAction">
<result>someAction.jsp</result>
</action>
bistå ?
Martin --
This e-mail communication and any attachments may contain confidential and privileged information for the use of the
designated recipients named above. If you are not the intended recipient, you are hereby notified that you have received
this communication in error and that any review, disclosure, dissemination, distribution or copying of it or its
contents
----- Original Message -----
From: <Ov...@posten.se>
To: <us...@struts.apache.org>
Sent: Thursday, December 07, 2006 3:32 AM
Subject: Struts2: How can I make a Filter redirecting to struts actions
Hi everybody,
I have experimented with a filter that triggers for keywords on the
request URL
and when found it should redirect to a struts action that processes the
keyword.
My dilemma is that I don't want to use:
response.sendRedirect("/some.action");
becoz redirect should be done internally in the servlet container, not
via browser.
I have tested:
request.getRequestDispatcher("/some.action").forward(request, response);
and it don't work. I guess becoz an action mapping is not a servlet, an
JSP page is.
Does anyone have an idea how to solve this? Any input welcome!
One approach could be to inherit:
org.apache.struts2.dispatcher.FilterDispatcher
and override doFilter() method and insert my keyword code. Kinda ugly
thou.
Regardings,
Ove Oldberg, Sweden.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
RE: Struts2: How can I make a Filter redirecting to struts actions
Posted by Martin Gainty <mg...@hotmail.com>.
Hi Ove
struts2 recommended way to establish a forward when your Action class
returns "success" is
to set the type attribute to "dispatcher" as in this example which forwards
to SverigeAltid.jsp
<result name="success" type="dispatcher">
<param name="location">/SverigeAltid.jsp</param>
</result>
i found this at
http://struts.apache.org/2.x/docs/result-configuration.html
HTH,
Martin --
______________________________________________
Disclaimer and confidentiality note
Everything in this e-mail and any attachments relates to the official
business of Sender. This transmission is of a confidential nature and Sender
does not endorse distribution to any party other than intended recipient.
Sender does not necessarily endorse content contained within this
transmission.
>
>Hi everybody,
>I have experimented with a filter that triggers for keywords on the
>request URL
>and when found it should redirect to a struts action that processes the
>keyword.
>
>My dilemma is that I don't want to use:
>response.sendRedirect("/some.action");
>becoz redirect should be done internally in the servlet container, not
>via browser.
>
>I have tested:
>request.getRequestDispatcher("/some.action").forward(request, response);
>and it don't work. I guess becoz an action mapping is not a servlet, an
>JSP page is.
>
>Does anyone have an idea how to solve this? Any input welcome!
>
>One approach could be to inherit:
>org.apache.struts2.dispatcher.FilterDispatcher
>and override doFilter() method and insert my keyword code. Kinda ugly
>thou.
>
>Regardings,
> Ove Oldberg, Sweden.
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org
>
_________________________________________________________________
View Athletes Collections with Live Search
http://sportmaps.live.com/index.html?source=hmemailtaglinenov06&FORM=MGAC01
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org