不知算不算问题
temp.jsp页面的内容如下:
<%@ page contentType= "text/html; charset=GBK " %>
<%@ page language= "java " import= "java.sql.* "%>
<html>
<head>
<title>
test the class
</title>
</head>
<body>
<%
request.getSession(true);
session.setAttribute( "test ", "suc ");
response.sendRedirect( "temp2.jsp ");
%>
</body>
</html>
temp2.jsp如下:
<%@ page contentType= "text/html; charset=GBK " %>
<%@ page language= "java " import= "java.sql.* "%>
<html>
<head>
<title>
test the class
</title>
</head>
<body>
<%
String temp=request.getParameter( "test ");
//String temp=session.getAttribute( "test ");
%>
<table width= "600 " border= "1 ">
<tr>
<td> <%=temp%> </td>
</tr>
</table>
</body>
</html>
结果却是NULL ,想不出问题在那
这两个文件都放在tomcat的ROOT 目录下
------解决方案--------------------request.getParameter( " ");取得是页面标签(文本框、下拉框……)或者是网址所带的参数,不能取session.setAttribute()或request.setAttribute()的值
------解决方案--------------------这句是错误的: String temp=request.getParameter( "test ");
这样是正确的:
String temp=String.valueOf(session.getAttribute( "test "));
------解决方案--------------------session.setAttribute( "test ", "suc ");
String temp=request.getParameter( "test ");
前面一页用得session后面用request
显然不对
得一致