struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eddie Bush <>
Subject Re: How-- html::form whose action is whatever action caused its display?
Date Mon, 25 Feb 2002 19:47:35 GMT
I believe the typical solution to this is an attribute set in either request
or session scope.  Your login action could then check to see if the
attribute exists, and forward to it if it does (and remove it, if it is in
the session).

Of course, your action knows it's own mapping, so it would set the attribute
before redirecting to login.

You'll probably need a hidden field in your login form if you choose to use
a request attribute - so you can keep the path across requests.

Of course, there is likely a better way - if someone knows one please chip
in =)

Hope that helps,

----- Original Message -----
From: "Jeff" <>
To: <>
Sent: Monday, February 25, 2002 1:30 PM
Subject: How-- html::form whose action is whatever action caused its

> What's the best/proper way to create a HTML:form whose "action" property
> set to whatever action caused the jsp template containing it to be
> in the first place?
> For example, suppose a form submission to / triggers an
> action class (say, "AdminAction") which determines that the user needs to
> log in before doing whatever it was that his original form submission was
> supposed to achieve. As luck would have it, the form bean just submitted
> a subclass of the login form bean (in fact, ALL of the application's form
> beans are subclasses of the login form bean so they'll be capable of doing
> double-duty as a login form bean while preserving the state of the
> formvars during a login sidetrip should the need arise). Anyway, the
> class returns mapping.findForward("login"), which is mapped to
> /templates/login.jsp. No sweat.
> Here's where things get sticky. The action class above ("AdminAction") is
> not the only one that might plausibly return mapping.findForward("login").
> Actually, every single action class (including "AdminAction" above) is a
> subclass of the abstract LoggedInUserAction class, which verifies that the
> user is logged in (and/or tries to log them in, if a username and password
> happens to have been submitted) before calling its own
> performLoggedInAction() abstract class, and returns
> mapping.findForward("login") if the user needs to log in.
> In other words, form submissions to /, /,
> /, and numerous other URLs map to Action classes
> are subclasses of LoggedInUserAction, any of which might plausibly result
> the return of mapping.findForward("login") if LoggedInUserAction realizes
> that the user hasn't logged in.
> The challenge is making sure that when login.jsp gets displayed because
> / fell through to login.jsp, the submitted login form gets
> sent to / If login.jsp gets displayed because
> / fell through to login.jsp, the submitted login form should
> get sent to / I know I -could- create a separate login form
> for every possible action, but I'm pretty sure that there's GOT to be a
> better way to do it. Like maybe a scripting variable whose value is
> URL resulted in the display of the current page?
> Suggestions?
> sample struts.xml excerpt:
> <form-beans type="org.apache.struts.action.ActionFormBean">
> <!-- all three form beans are subclasses of LoginFormBean -->
>  <form-bean name="createForm" type="pkg.CreateFormBean">
>  <form-bean name="previewForm" type="pkg.PreviewFormBean">
>  <form-bean name="updateForm" type="pkg.UpdateFormBean">
> </form-beans>
> <global-forwards type="org.apache.struts.action.ActionForward>
>  <forward name="peon" path="/not_allowed.jsp">
>  <!-- when the "login" mapping is called, it needs to use whatever
bean -->
>  <!-- was associated with the original action in the action-mappings
> below -->
>  <forward name="login" path="/login.jsp">
> </global-forwards>
> <action-mappings type="org.apache.struts.action.ActionMapping">
>  <action path="/create" type="pkg.CreateAction" name="createForm">
>   <forward name="create" path="/create.jsp">
>  </action>
>  <action path="/preview" type="pkg.PreviewAction" name="previewForm">
>   <forward name="preview" path="/preview.jsp">
>  </action>
>  <action path="/update" type="pkg.UpdateAction" name="updateForm">
>   <forward name="update" path="/update.jsp">
>  </action>
> </action/mappings>
> sample login.jsp excerpt:
> <html:form action="/">
> <!-- assuming this jsp was displayed as a result of a form submission
> to / If the form submission resulting in this page's display
> were to /, the action needs to be "/", and so on.
> Perhaps something like... -->
> <%--
> <html:form
> action="<%=URL_from_which_the_display_of_this_page_was_launched%>">
> --%>
> </html:form>
> --
> To unsubscribe, e-mail:
> For additional commands, e-mail:

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message