tags:

views:

54

answers:

1

Hi ,

I have a JSP in which i am redirecting to another jsp like ,i dont have any other data in that jsp,i want to pass a value from this jsp(index.jsp) to the redirected jsp(login.jsp),how will i do this?

Here "logonInput" is defined in struts-config.xml

index.JSP is like

<%@ page language="java" contentType="text/html;charset=UTF-8"%>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%
String sessionExpired=(String)request.getAttribute("SessionExpired");
%>

<logic:redirect forward="logonInput"/>

I want to display or pass the value sessionExpired to login.jsp

A: 

To forward a parameter using a session:

In your first jsp page.

session.setAttribute("sessionExpired", sessionExpired);

To read:

session.getAttribute("sessionExpired");

To forward a parameter using in the request:

request.setAttribute("sessionExpired", sessionExpired);

Forward parameter using jsp forward tag:

<jsp: forward page="login.jsp">
  <jsp: param name="sessionExpired" value='<%request.getParameter("sessionExpired")%>'/> 
</jsp: forward>

Forward parameter using logic:redirect: Edit Add the parameter to the request.

<%request.setAttribute("sessionExpired",sessionExpired);%>

This will pass the parameter set in the initial request parameter to the forwarded page.

<logic:redirect forward=login.jsp" paramId="sessionExpired" paramName="sessionExpired" />

To read:

String sessionExpired=(String)request.getAttribute("sessionExpired");
Gordon
i dont want to use session
sarah
This is fine,is there a way to pass the value along with <logic:redirect forward="logonInput"/>
sarah
How to read these values in login.jsp ? paramId ??
sarah
Ya session approach do works fine,i am aware of it,i wanted something passed along with <logic:redirect forward="logonInput"/>
sarah
<logic:redirect forward=login.jsp" paramId="sessionExpired" paramName="<%= sessionExpired%>" /> in index.jsp and login.jsp wil have String sessionExpired=(String)request.getAttribute("sessionExpired");is not working,wil get an error saying no scope is defined
sarah
<logic:redirect forward=login.jsp" paramId="sessionExpired" paramName="sessionExpired" />This line should just forward the original parameter. The other line will add a parameter of the name of the value of sessionExpired.
Gordon
Cannot find bean: "sessionExpired" in any scope is the error after using <logic:redirect forward=login.jsp" paramId="sessionExpired" paramName="sessionExpired" />
sarah
Same error even after adding the data in request scope
sarah
Make sure redirect="true" isn't set in your action mapping this will create a new request when the page is forwarded.
Gordon
did not worked out even after removing rediect=true,anyways i am goingto use session approach,thanks a lot
sarah
It's probably something small. I will update my answer if I find it.
Gordon