struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrew Hill" <andrew.david.h...@gridnode.com>
Subject RE: Passing a request parameter within Struts framework
Date Mon, 07 Oct 2002 12:40:38 GMT
Had another look at your question and realised it is attributes rather than
parameters (Im always getting these mixed up!) that you stated in your
original question! (hehe guess my response was too quick!).
Given that this is the case, it should be useable in the next page unless
the forward is a redirecting forward.
Dont use jsp much so cant remember the 'best' way to expose it to the page,
but you could probably use a runtime expression thinghy (<%=
request.getAttribute("selTopNav"); %>

If however you need it as a request parameter the way I always do it is as
mentioned below and heres some code to illustrate:

firstly a simple method for adding parameters onto urls:
(btw: you can probably lose the first half of that "if" - Im just paranoid
about nulls ;->)

public static String addParameterToURL(String url, String parameter, String
value)
{
  if(url == null)
  {
    return parameter + "=" + value;
  }
  else
  {
    return url + ( (url.indexOf("?")==-1) ? "?" : "&" ) + parameter + "=" +
value;
  }
}

and to use this with forwards:

ActionForward fwd = mapping.findForward( target );
String path = addParameterToURL(forward.getPath(),"selTopNav","1");
ActionForward newFwd = new ActionForward(path,fwd.getRedirect() );
return newFwd;

-----Original Message-----
From: Tuan H. Le [mailto:tuan.le@phsadc.com]
Sent: Monday, October 07, 2002 20:19
To: Struts Users Mailing List
Subject: RE: Passing a request parameter within Struts framework


Andrew,

Thanks for a quick response! Do you have a sample code that I can use? It
seems to me that are several lines of code to complete your suggestion. Is
this the only way to pass a request parameter within the LoginAction to
another JSP page? Eventually, I need to pass the request parameter selTopNav
(the user's selected tab) value back and forth to determine which tab the
user has selected.

Thanks again!
Tuan

-----Original Message-----
From: Andrew Hill [mailto:andrew.david.hill@gridnode.com]
Sent: Monday, October 07, 2002 5:07 AM
To: Struts Users Mailing List
Subject: RE: Passing a request parameter within Struts framework


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:
<mailto:struts-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail:
<mailto:struts-user-help@jakarta.apache.org>


--
To unsubscribe, e-mail:
<mailto:struts-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail:
<mailto:struts-user-help@jakarta.apache.org>


--
To unsubscribe, e-mail:   <mailto:struts-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:struts-user-help@jakarta.apache.org>


Mime
View raw message