I can think of shonky ways around this, but I'm obviously missing something Struts related in order to make this work cleanly. Any guidance would be appreciated.
It's not actually a Struts issue you are encountering, rather the standard HTTP request-response cycle.
Your first link adds the parameter appName to the request. When the destination is rendered that request no longer exists. So while it was available to mailin.jsp when that jsp was being rendered (since at that time the request was still active), once it's finished, the request is gone along with any information it contained. When you submit mailin.jsp to an Action, a completely new request is generated, and this is why appName is null.
Let me add another comment which will help you out in the long run with Struts. You should never be linking directly to the JSPs that make up your application. All requests should go through the controller (the ActionServlet) and therefore all links to views in your application should be mapped to Actions, even if that Action is a simple ForwardAction.
So in your case, instead of linking directly to mailin.jsp it would have been better to link to an Action. That Action could have placed appName into Session in order to be retrieved later, or if you wanted to keep it in the request, it could have populated an appName field for the mailDetailsForm therefore making appName available in the request when that form was submitted.
The problem here is that Parameters last through only one request. When you displayed mailin.jsp, you are in the same request context where the parameter was passed so there you have access to it. When you submit mailin.jsp, thereby calling MailAction you have started a new request context, and the parameter associated with the previous request is gone. If you want to pass the paraemeter from the jsp on to the action it calls, I'd suggest using a hidden field as in:
This is going to be a generic mail in database that will be linked from several parts of a website. Depending on which part of the site it was initiated from, I was intending to pass a request variable to determine which content the requester was asking for.
As Jason has pointed out above, I should be linking to an Action and setting a session attribute there. So, should I have a separate Action for each parameter I should be passing ?
and ColourAction sets a session attribute "appName" to "colour" before forwarding to the original mailin.jsp.
Then, to link from a second part of the site, which would have been
and BWAction sets "appName" to "bw" etc.
Do I have to generate a superfluous ActionForm for each of these Actions ?
[ March 20, 2005: Message edited by: Niall McLoughlin ] [ March 20, 2005: Message edited by: Niall McLoughlin ]
Joined: Feb 15, 2005
You can still append a parameter to a call to an action as in mailin.do?appname=colour. You are free to make as many or few action classes and ActionForms as make sense for your application. If the various jsp's to be displayed by the mailin action are similar, you could easily make each of them use the same ActionForm. If they're substantially different, you could make them use different ActionForms.
The point here is that the Action class should get called first, and based on input received from the user, make the decision as to what jsp should be displayed next.
Joined: Mar 11, 2002
subject: variable in request in jsp, not in Action ?