문제

index.jsp:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Login</title>
</head>
<body>
<h1>
<font color=orange ><center> Authentification </font> </h1>
<form name"loginform" action="login" method="post">
<p> Enter your ID: <input type="text" name="id"><br>
<input type="submit">

</form>
</body>
</html>

Authentification.java:

  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            HttpSession session = request.getSession();

            int IdUser = Integer.valueOf(request.getParameter("id"));
            session.setAttribute("ide", IdUser);

            try {

                if(auth.authen(IdUser)){
                    session=request.getSession();

                       request.getRequestDispatcher("acceuil.jsp").forward(request, response);
                       System.out.println("found");}
                else{
                       request.getRequestDispatcher("index.jsp").forward(request, response);
                      System.out.println("not found");
                }

            } catch (SQLException e) {

                e.printStackTrace();
            }


        }

acceuil.jsp: Where I want to display IdUser

 <% Integer idUser = (Integer)session.getAttribute("IdUser"); %>
<!--some HTML code--> 
<div id="corps"><h1>
        Welcome <%=idUser%> </h1></div>

So what I want to have is after the user enter's his id and if the id is found in the database(this operation works) there would be a message ncluding the user's id. the get.Attribute doesn't return a value instead in my page the result is "Welcome NULL".

올바른 솔루션이 없습니다

다른 팁

You saved the attribute in session with name "ide" but try to recover it with name "IdUser". Use the same attribute name in both places.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top