You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Tuan H. Le" <tu...@phsadc.com> on 2002/10/07 14:00:43 UTC
Passing a request parameter within Struts framework
Hi,
How do I pass a request attribute to another form? In my case, after a successful login, it would forward the user to
the main form (MainMeu.jsp which has a frameset). In the main form, it has several tabs. By default, it displays the
first tab.
Currently, in the perform() method of LoginAction class, I have the following code
//...
request.setAttribute( "selTopNav", "1" );
return( mapping.findForward( target ) );
Here's the code for the MainMenu.jsp
<%@ page language="java" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<!-- frame -->
<HTML>
<HEAD>
<TITLE><bean:message key="app.label.title" /></TITLE>
</HEAD>
<frameset rows="159,*,125" frameborder="0" noresize framespacing="0">
<frame src="Top.jsp" name="top" id="top" frameborder="0" scrolling="no" noresize marginwidth="0" marginheight="0" framespacing="0">
<frameset cols="95%,*" framespacing="0">
<frame src="Mid.jsp" name="mid" marginwidth="0" marginheight="0" scrolling="yes" frameborder="0" noresize framespacing="0">
<frame src="RightSide.jsp" name="rightSide" marginwidth="10" marginheight="10" scrolling="no" frameborder="0" noresize framespacing="0">
</frameset>
<frame src="Bottom.jsp" name="btm" id="btm" frameborder="0" scrolling="no" marginwidth="0" marginheight="0" noresize framespacing="0">
</frameset>
<noframes>
<bean:message key="app.msg.noframe" />
</noframes>
</html>
And, in the Top.jsp, I have a test code to get a value of the request attribute, but it always returns a null value
Top Nav: <%= request.getParameter( "selTopNav" ) %>
Here's a partial of my struts-config.xml file
<form-beans>
<form-bean name="loginForm" type="com.phs.ezhr.presentation.form.LoginForm" />
<form-bean name="mainMenuForm" type="com.phs.ezhr.presentation.form.MainMenuForm" />
</form-beans>
<global-forwards>
<forward name="login" path="/Login.jsp"/>
</global-forwards>
<!-- Action Mapping Definitions -->
<action-mappings>
<!-- Process a user login -->
<action path="/login"
type="com.phs.ezhr.presentation.action.LoginAction"
validate="true"
input="/Login.jsp"
name="loginForm"
scope="session" >
<forward name="success"
path="/MainMenu.jsp" />
<forward name="failure"
path="/Login.jsp" />
</action>
<!-- Process a user logoff -->
<action path="/logoff"
type="com.phs.ezhr.presentation.action.LogoffAction">
<forward name="success" path="/login.jsp" />
</action>
<action path="/top"
type="com.phs.ezhr.presentation.action.MainMenuAction"
validate="false"
input="/Top.jsp"
name="mainMenuForm"
scope="request" >
</action>
</action-mappings>
Do you know what I'm missing?
Thanks,
Tuan
Re: Passing a request parameter within Struts framework
Posted by Luca Zago <lz...@e-tree.com>.
Hi,
your problem is clear, and it has very few solutions :)
The problem is that you use frames. Every Frame in a different request,
then the request from your form..end at the page containing the
frameset, and your request with your parameters set in your form ends
here. All the pages inside the frames are different GET requests from
the browser, then they cannot have access your parameters and
attributess (belonging to you former request).
Solutions:
if your parameter is only a string you can build a string chain..in the
src of your frame tag:
<frame
src="Top.jsp?myparameterName=<%=request.getParameter("myparameterName")%>"
name="top" id="top" frameborder="0" scrolling="no" noresize
marginwidth="0" marginheight="0" framespacing="0">
In this case your new request wll have the parameter named myparameterName.
It's very unelegant solution but it could work
Second put your object in the user's session. it's resonable to put it
in session after all, if I understand well, is an attribute of a user's
profile.
A general suggestions, don't user frames in dynamic pages, you can have
always problems with them, Jsp has a nice templating machanism, use that
to build your header or footer.
Tuan H. Le wrote:
> Hi,
>
> How do I pass a request attribute to another form? In my case, after a successful login, it would forward the user to
> the main form (MainMeu.jsp which has a frameset). In the main form, it has several tabs. By default, it displays the
> first tab.
>
> Currently, in the perform() method of LoginAction class, I have the following code
>
> //...
> request.setAttribute( "selTopNav", "1" );
> return( mapping.findForward( target ) );
>
>
> Here's the code for the MainMenu.jsp
>
>
> <%@ page language="java" %>
> <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
> <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
>
> <!-- frame -->
> <HTML>
> <HEAD>
> <TITLE><bean:message key="app.label.title" /></TITLE>
> </HEAD>
> <frameset rows="159,*,125" frameborder="0" noresize framespacing="0">
> <frame src="Top.jsp" name="top" id="top" frameborder="0" scrolling="no" noresize marginwidth="0" marginheight="0" framespacing="0">
> <frameset cols="95%,*" framespacing="0">
> <frame src="Mid.jsp" name="mid" marginwidth="0" marginheight="0" scrolling="yes" frameborder="0" noresize framespacing="0">
> <frame src="RightSide.jsp" name="rightSide" marginwidth="10" marginheight="10" scrolling="no" frameborder="0" noresize framespacing="0">
> </frameset>
> <frame src="Bottom.jsp" name="btm" id="btm" frameborder="0" scrolling="no" marginwidth="0" marginheight="0" noresize framespacing="0">
> </frameset>
> <noframes>
> <bean:message key="app.msg.noframe" />
> </noframes>
> </html>
>
>
> And, in the Top.jsp, I have a test code to get a value of the request attribute, but it always returns a null value
>
> Top Nav: <%= request.getParameter( "selTopNav" ) %>
>
> Here's a partial of my struts-config.xml file
>
> <form-beans>
> <form-bean name="loginForm" type="com.phs.ezhr.presentation.form.LoginForm" />
> <form-bean name="mainMenuForm" type="com.phs.ezhr.presentation.form.MainMenuForm" />
> </form-beans>
>
> <global-forwards>
> <forward name="login" path="/Login.jsp"/>
> </global-forwards>
>
> <!-- Action Mapping Definitions -->
> <action-mappings>
> <!-- Process a user login -->
> <action path="/login"
> type="com.phs.ezhr.presentation.action.LoginAction"
> validate="true"
> input="/Login.jsp"
> name="loginForm"
> scope="session" >
> <forward name="success"
> path="/MainMenu.jsp" />
> <forward name="failure"
> path="/Login.jsp" />
> </action>
> <!-- Process a user logoff -->
> <action path="/logoff"
> type="com.phs.ezhr.presentation.action.LogoffAction">
> <forward name="success" path="/login.jsp" />
> </action>
> <action path="/top"
> type="com.phs.ezhr.presentation.action.MainMenuAction"
> validate="false"
> input="/Top.jsp"
> name="mainMenuForm"
> scope="request" >
> </action>
> </action-mappings>
>
>
> Do you know what I'm missing?
>
> Thanks,
> Tuan
>
>
>
>
> ------------------------------------------------------------------------
>
> --
> To unsubscribe, e-mail: <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
--
Luca Zago
Senior IT Developer
_____________________________________________________
E-TREE S.p.a. Via Fonderia 43 - 31100 Treviso (Italy)
phone +39.0422.3107
fax +39.0422.310888
http://www.e-tree.com http://www.webanana.com
_____________________________________________________
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
RE: Passing a request parameter within Struts framework
Posted by Andrew Hill <an...@gridnode.com>.
In your action you can create a new forward object and return that.
ie: get the forward for target, extract its url and append required
parameter(s) and create a new forward using that and the redirect value from
the one you looked up, and return the new one.
> -----Original Message-----
> From: Tuan H. Le [mailto:tuan.le@phsadc.com]
> Sent: Monday, October 07, 2002 20:01
> To: Struts Users Mailing List (E-mail)
> Subject: Passing a request parameter within Struts framework
>
> Hi,
>
> How do I pass a request attribute to another form? In my case, after a
successful login, it would forward the user to
> the main form (MainMeu.jsp which has a frameset). In the main form, it has
several tabs. By default, it displays the
> first tab.
>
> Currently, in the perform() method of LoginAction class, I have the
following code
>
> //...
> request.setAttribute( "selTopNav", "1" );
> return( mapping.findForward( target ) );
>
>
> Here's the code for the MainMenu.jsp
>
>
> <%@ page language="java" %>
> <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
> <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
>
> <!-- frame -->
> <HTML>
> <HEAD>
> <TITLE><bean:message key="app.label.title" /></TITLE>
> </HEAD>
> <frameset rows="159,*,125" frameborder="0" noresize framespacing="0">
> <frame src="Top.jsp" name="top" id="top" frameborder="0"
scrolling="no" noresize marginwidth="0" marginheight="0" framespacing="0">
> <frameset cols="95%,*" framespacing="0">
> <frame src="Mid.jsp" name="mid" marginwidth="0" marginheight="0"
scrolling="yes" frameborder="0" noresize framespacing="0">
> <frame src="RightSide.jsp" name="rightSide" marginwidth="10"
marginheight="10" scrolling="no" frameborder="0" noresize framespacing="0">
> </frameset>
> <frame src="Bottom.jsp" name="btm" id="btm" frameborder="0"
scrolling="no" marginwidth="0" marginheight="0" noresize framespacing="0">
> </frameset>
> <noframes>
> <bean:message key="app.msg.noframe" />
> </noframes>
> </html>
>
>
> And, in the Top.jsp, I have a test code to get a value of the request
attribute, but it always returns a null value
>
> Top Nav: <%= request.getParameter( "selTopNav" ) %>
>
> Here's a partial of my struts-config.xml file
>
> <form-beans>
> <form-bean name="loginForm"
type="com.phs.ezhr.presentation.form.LoginForm" />
> <form-bean name="mainMenuForm"
type="com.phs.ezhr.presentation.form.MainMenuForm" />
> </form-beans>
>
> <global-forwards>
> <forward name="login" path="/Login.jsp"/>
> </global-forwards>
>
> <!-- Action Mapping Definitions -->
> <action-mappings>
> <!-- Process a user login -->
> <action path="/login"
> type="com.phs.ezhr.presentation.action.LoginAction"
> validate="true"
> input="/Login.jsp"
> name="loginForm"
> scope="session" >
> <forward name="success"
> path="/MainMenu.jsp" />
> <forward name="failure"
> path="/Login.jsp" />
> </action>
> <!-- Process a user logoff -->
> <action path="/logoff"
> type="com.phs.ezhr.presentation.action.LogoffAction">
> <forward name="success" path="/login.jsp" />
> </action>
> <action path="/top"
> type="com.phs.ezhr.presentation.action.MainMenuAction"
> validate="false"
> input="/Top.jsp"
> name="mainMenuForm"
> scope="request" >
> </action>
> </action-mappings>
>
>
> Do you know what I'm missing?
>
> Thanks,
> Tuan
>
> << File: ATT00078.txt >>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>