I had tried to pass string from servlet to jsp .But it never forwarded to jsp .The following are the files
servlet file:
String login = "asd";
request.setAttribute("myname",login);
request.getRequestDispatcher("GetCategory.jsp").forward(request, response);
jsp file:
<% String name = (String)request.getAttribute("myname");
System.out.println(name);%>
I am a bit rusty in that topic but i think i used the forwarding this way:
String nextJSP = "/searchResults.jsp";
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(nextJSP);
dispatcher.forward(request,response);
So getting the RequestDispatcher from the ServletContext rather than from the request, but im not sure if there is any difference behind the scenes of both calls.
Edit: Where do you set that attribute? (Is it in one of the two Methods doGet/doPost?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With