Why does the servlet send a null value to the JSP page instead of a text string? Here is the servlet and the doGet () method :

@Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setAttribute("myresult", "Proba"); RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/mypage.jsp"); dispatcher.forward(request, response); } 

Here is a snippet from mypage.jsp:

 <form ACTION = "/servlet/ShowParameters" method = "post" id = "formId"> <div> <table id = "myTable" width="100%"> <tr> <td><%= request.getAttribute("myresult") %></td> </tr> </table> </div> </form> 

Expected value of Proba , and I receive null ?

Tried to make an empty page mypage.jsp . Make sure - this is the one that is displayed. She's the only one with me.

  • stack trace to studio - GenCloud
  • stack trace? What is it like? Tell me how to get it? - Vard32
  • By the way, I checked dispatcher for null - it’s not equal to null - Vard32
  • And you check how? mypage.jsp go directly to mypage.jsp or through a servlet? - Roman
  • one
    Do you even know what a servlet is and how it binds to a URL? - Roman

1 answer 1

Hello.

change the POST method to GET in the form mypage.jsp

 <form ACTION = "/servlet/ShowParameters" method = "GET" id = "formId"> <div> <table id = "myTable" width="100%"> <tr> <td><%= request.getAttribute("myresult") %></td> </tr> </table> </div> </form>