JSP重定向和传递值 [英] JSP Redirection and passing value
问题描述
我有一个JSP,我将其重定向到另一个jsp,如
,我在该jsp中没有任何其他数据,我想将此jsp(index.jsp)中的值传递给重定向的jsp( login.jsp),我该怎么做?
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?
这里logonInput在struts-config.xml中定义
Here "logonInput" is defined in struts-config.xml
index.JSP就像
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"/>
我想显示或传递值sessionExpired到login.jsp
I want to display or pass the value sessionExpired to login.jsp
推荐答案
使用会话转发参数:
在您的第一个jsp页。
In your first jsp page.
session.setAttribute("sessionExpired", sessionExpired);
阅读:
session.getAttribute("sessionExpired");
要在请求中转发参数:
request.setAttribute("sessionExpired", sessionExpired);
使用jsp转发代码转发参数:
<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" />
阅读:
String sessionExpired=(String)request.getAttribute("sessionExpired");
这篇关于JSP重定向和传递值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!