JSP Redirection and passing value

谁说我不能喝 提交于 2020-01-02 08:56:08

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!