问题
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
回答1:
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");
来源:https://stackoverflow.com/questions/3226970/jsp-redirection-and-passing-value