<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> </head>
<body> <center><%Object userNameObj = request.getSession(false).getAttribute("userName"); String userName = new String(); userName = userNameObj != null ? userName.toString() : "Hey, guy. You haven't signed on yet.Get to sign on first then you are alowed to use this page.";%> <h1>Hello! <%=userName %></h1> </center> </body> </html>
改成response.sendRedirect("succeed.jsp?s_name="+username);
因为session他只保存一次页面跳转后的值,如果要继续为下一页服务,就要传参
<%
String s_name="";
String s_pass="";
s_name=request.getParameter("username");
s_pass=request.getParameter("password");
if("admin".equals(s_name)&&"pass".equals(s_pass))
{
request.getSession(false).setAttribute("userName", s_name);
response.sendRedirect("success.jsp");
response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
response.setHeader("Location","success.jsp");
}
else
{
response.sendRedirect("login.jsp");
response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
response.setHeader("Location","login.jsp");
}
%>
<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body>
<center><%Object userNameObj = request.getSession(false).getAttribute("userName");
String userName = new String();
userName = userNameObj != null ? userName.toString() : "Hey, guy. You haven't signed on yet.Get to sign on first then you are alowed to use this page.";%>
<h1>Hello! <%=userName %></h1>
</center>
</body>
</html>
这里应该用转发