如何使用JavaScript检索会话值?

时间:2014-05-13 12:47:35

标签: javascript session

public class LoginServlet extends HttpServlet{

private static final long serialVersionUID = 1L;

public void doPost(HttpServletRequest request, HttpServletResponse response)  
        throws ServletException, IOException {  

    response.setContentType("text/html");  
    PrintWriter out = response.getWriter();  

    String n=request.getParameter("username");  
    String p=request.getParameter("userpass"); 

    HttpSession session = request.getSession(false);
    if(session!=null)
    session.setAttribute("name", n);

    if(LoginDao.validate(n, p)){  
        RequestDispatcher rd=request.getRequestDispatcher("indexLogged.html");  
        rd.forward(request,response);  
    }  
    else{  
        out.print("<p style=\"color:red\">Sorry username or password error</p>"); 
        RequestDispatcher rd=request.getRequestDispatcher("index.jsp");  
        rd.include(request,response);  
    }  

    out.close();  
}  

我有如上所示的代码。我有这个servlet,我想做的是在JavaScript中检索会话变量,但我不知道如何做到这一点。谁能帮我? 谢谢!

0 个答案:

没有答案