I started to learn servlets and JSP, I ran into a problem: the JSP did not get requests:

request.getRequestDispatcher("index.jsp"); ArrayList users = new ArrayList(); try { EasyDB db = connectDB("postgres", "wasd123wasd5" , "javaTest"); users = db.MakeQuerry("SELECT \"Name\", \"Password\", \"ID\", \"FullName\"\n" + " FROM \"Users\";\n"); } catch (SQLException e) { e.printStackTrace(); } request.setAttribute("users", users); System.out.println(users); request.getRequestDispatcher("index.jsp").forward(request, response); } 

This is a servlet, I pass the variable users to it, this is an ArrayList , and I know that users !=null , but nothing comes to JSP:

 <% out.print(request.getAttribute("users")); %> 

this code is null , I’ve checked it a hundred times, all of a sudden, users are still null , but in the console and with all the other ways of checking users all the same something exactly what I need, help, what to do? Just like in the examples on the Internet.

    1 answer 1

    try to change

     request.setAttribute("users", users); 

    on

     response.setAttribute("users", users); 
    • What does it have to do with it? Response does not have a setAttribute method at all, you can look at the Internet, in all examples it works this way - NEStenerus nester
    • pass through the parameters - setParameter (), getParameter () - Oleksiy Morenets
    • @NEStenerusnester yes sorry, I looked at your code. It looks right in general, can you throw your project code onto the githab? I'll try to check it out for myself. - Ishikawa Yoshi
    • Interesting, I created a new servlet and a new jsp and hung up a new servlet on url /abc , everything comes in perfectly, but the old one that hangs on the standard link / for some reason does not come, do not explain? - NEStenerus nester