从会话HTTPServletRequest获取xhtml中的属性

时间:2017-02-16 09:32:05

标签: java jsf xhtml

我是新手,所以我在基于jsf的应用程序中有点绿。我试图在dashboard.xhtml页面中显示set属性

这是我的 servlet 类:

  public class LoginServlet extends HttpServlet{
  public void doPost(HttpServletRequest request,HttpServletResponse response)throws ServletException, IOException {

 String username = request.getParameter("username");   
 String password = request.getParameter("password");

 LoginDAO loginService = new LoginDAO();
 boolean result = loginService.authenticateUser(username, password);
 Users users = loginService.getUserByuserName(username); 

 if(result == true ){
    request.getSession().setAttribute("user", users);          
    System.out.println("user"+users.getuserName());
    response.sendRedirect("dashboard.xhtml");
 }
 else{
     response.sendRedirect("error.jsp");
 }
}
}

dashboard.xhtml:

  <!DOCTYPE html>
  <html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:h="http://java.sun.com/jsf/html">
<head>
    <title>DASHBOARD</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head>
<body>      
    <h:outputText value="#{user.username)}"/> 
</body>

但是,它没有显示任何内容?我错过了什么?任何帮助将不胜感激。谢谢!

0 个答案:

没有答案