jsp与jsp页面之间的传值
*****用< %=request.getParameter(“参数名”)% >和${ param.参数名 }来接收 。其中< %=request.getParameter(“参数名”)% >等价于${ param.参数名 }
1.<a href="thexuan.jsp?action=transparams&detail=directe">直接传递参数</a>
2.在使用response.sendRedirect一类的页面转向的时候,也可以用如下代码:
response.sendRedirect("thexuan.jsp?action=transparams&detail=directe")
都用request.getParameter(name)取得参数
3.实现主页面向包含页面传递参数,如下:
<jsp:include page="jsp的URL">
<jsp:param name="param name" value="paramvalue"/>
</jsp:include>
用request.getParameter(name)取得参数
4.实现在使用jsp:forward动作做页面跳转时传递参数,如下:
< jsp:forward page="Relative URL">
< jsp:param name="paramname" value="paramvalue" />
< /jsp:forward> 通过这种方式和一般的表单参数一样的,
通过request.getParameter(name)取得参数
(3)设置session和request
实例说明:
session1.jsp(从表单输入usernmae,将该参数传递到session2.jsp)
<meta http-equiv="Content-Type"content="text/html;charset=gbk"/>
<html>
<body>
<form method="post" action="session2.jsp">
name:<input type="text" name="username">
<input type="submit" value="submit"">
</form>
</body>
</html>
@@@@@@@@@@
session2.jsp
(接收session1.jsp传递过来的参数username,存到session中,然后在将参数place通过表单提交到session3.jsp中)
<%@ page language="java" contentType="text/html; charset=gb2312"%>
<html>
<body>
<%String username = request.getParameter("username"); // request.getParameter() 取得是通过容器的实现来取得通过类似post,get等方式传入的数据
session.setAttribute("username",username);%>
hello,<%=username%>!the place you want to go is <p>
<form method="post" action="session3.jsp">
<input type=text name="placei">
<p>
<input type=submit value="submit">
</form>
</body>
</html>
@@@@@@@@@@@
session3.jsp
(接收session2.jsp传递过来的参数place,并从session中读取参数username),输出
<%@ page language="java" contentType="text/html; charset=gb2312"%>
<html>
<body>
<% String username = (String) session.getAttribute("username");
String place = request.getParameter("place"); %>
<%= username %>
<br> the place you want to go is <br>
<%=place%>
</body>
</html>
本文详细介绍了在JSP页面间通过请求参数进行数据传递的方法,包括直接参数传递、页面转向时的参数获取,以及如何在包含页面和使用jsp:forward动作时传递参数。此外,文章还阐述了如何利用Session对象实现状态信息的持久化存储与跨页面传递,通过实例展示了从主页面接收参数、存储至Session并转发到下一个页面的过程。
212

被折叠的 条评论
为什么被折叠?



