Hi,

I added Andrew's code tip as below, but it still returns a null value for the request 
parameter.

public final class LoginAction extends Action {
  public ActionForward perform( .... ) {
    // . . .
    ActionForward curForward = mapping.findForward( target );
    String path = URLUtil.addParameterToURL( curForward.getPath(), "selTopNav", "1" );
    System.out.println( path );
    ActionForward newForward = new ActionForward( path, curForward.getRedirect() );
    return newForward;
  }
}

public class URLUtil {
  public static String addParameterToURL( String anURL,
                                          String aParameter,
                                          String aValue ) {
    if ( anURL == null ) {
      return aParameter + "=" + aValue;
    } else {
      return anURL + ( (anURL.indexOf( "?" ) == -1) ? "?" : "&" ) + aParameter + "=" + 
aValue;
    }
  }
}

------ MainMenu.jsp (where it get forwarded to for a successful login -----
<%@ 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>

---- Top.jsp (a frame within a frameset and where the request.getParameter get called) 
------

Selected Top Nav: <%= request.getParameter( "selTopNav" ) %>


This returns a null value instead of "1".

I must have missed some thing here.

Thanks,
Tuan



-----Original Message-----
From: Tuan H. Le 
Sent: Monday, October 07, 2002 6:02 AM
To: Struts Users Mailing List
Subject: RE: Passing a request parameter within Struts framework


Andrew,

Thanks again for your help! I'm going to try your suggestion soon.

Tuan

-----Original Message-----
From: Andrew Hill [mailto:[EMAIL PROTECTED]]
Sent: Monday, October 07, 2002 5:41 AM
To: Struts Users Mailing List
Subject: RE: Passing a request parameter within Struts framework


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:[EMAIL PROTECTED]]
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:[EMAIL PROTECTED]]
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:[EMAIL PROTECTED]]
> 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:[EMAIL PROTECTED]>
For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>


--
To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to