login.jsp <% String name = request.getParameter("name"); String passsword = request.getParameter("password"); if(name.equals("tomuno")&&password.equals("csdn")) { session.setAttribute("name",name); response.sendRedirect("success.jsp"); } else{ response.sendRedirect("login.jsp"); } %>success.jsp who am i: <%=session.getAttribute("name")%>
我运行你的程序 if(name.equals("tomuno") && password.equals("csdn"))这里报错阿不过我看应该没错阿 c:\jakarta-tomcat-4.0\work\localhost\_\_0002fsducn_0005fshop_0002ftest_0002flogin_0002ejsplogin_jsp_0.java:59: Undefined variable or class name: password if(name.equals("tomuno") && password.equals("csdn")) ^ 错误就是这个
1.request.getSession() will return a session whether the session exists or not2.so in common, we always set some Object into session, and if the object not here then you can know the one must be the first time here!3.common usage is request.getAttribute() not request.getParameter()!
String username=(String)session.getAttribute("username");// if (username != null){ session已经获得 }
<%
System.out.println(session.getAttribute("username"));
%>
String username = request.getParameter("username") ;如果没有成功登录的话不会返回首页
取得session属性 session.getAttribute("username");
session为容器对象 与登录用户无关
String username = request.getParameter("username") ;
%>
我这样得到
<%=username%>
这样显示是NULL的结果
<%=session.getAttribute("username")%>
这样显示是username的结果这里的username不是用户名就是字符串"username"
Redirect重定向
消毁request对象
消毁request对象
何session有什么关系?
谢谢
<%
String name = request.getParameter("name");
String passsword = request.getParameter("password");
if(name.equals("tomuno")&&password.equals("csdn"))
{
session.setAttribute("name",name);
response.sendRedirect("success.jsp");
}
else{
response.sendRedirect("login.jsp");
}
%>success.jsp
who am i:
<%=session.getAttribute("name")%>
if(name.equals("tomuno") && password.equals("csdn"))这里报错阿不过我看应该没错阿
c:\jakarta-tomcat-4.0\work\localhost\_\_0002fsducn_0005fshop_0002ftest_0002flogin_0002ejsplogin_jsp_0.java:59: Undefined variable or class name: password
if(name.equals("tomuno") && password.equals("csdn"))
^
错误就是这个
if (username != null){
session已经获得
}
还是 tomuno(tomuno) 老兄的好
虽然有问题不过他总归明白我的意思
password not passsword