jsp的属性

来源:百度知道 编辑:UC知道 时间:2024/06/15 22:52:51
index.jsp
<%@ page contentType="text/html;charset=GB2312" %>

<html>
<body>
<%request.setAttribute("b","bbbbb");%>
<form action="out.jsp">
<input type="submit">
</form>
</body>
</html>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

out.jsp
<html>
<body>
<% out.print(request.getAttribute("b")); %>
</body>
</html>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
为什么在out.jsp里打印不出b的值?打印的是NULL

request.setAttribute的值不在页面间传递。
通常来说,可用以下方式:
1、把request改为session
2、将参数放在action的url字符串后面,即<form action="out.jsp?b=bbbb" method="post">,注意method一定是post,不是get。
3、通过隐藏字段提交,即在form中增加<input type=hidden name="b" value="bbbb">,method可以是get也可以是post

<%request.setAttribute("b","bbbbb");%> 放到form里面试试