• Post Reply Bookmark Topic Watch Topic
  • New Topic

Values from Servlet to JSP  RSS feed

 
rossella catalano
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a problem with some values from Servlet page to JSP page.
I want to show some values on JSP page, I have this Servlet code:

protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);

HttpSession session = request.getSession(true);
response.setContentType("text/html");
session.setAttribute("SogliaMin", "200");
session.setAttribute("SogliaMax", "500");
response.sendRedirect("ProvaCrosshair.jsp");
}

And I have use this code to show them on jsp page:
${SogliaMin}: ${SogliaMax}

The problem is that the first time I can't see the value but if I press F5(if I refresh the page) I can see them!
Can someone help me?
Thanks


 
Swastik Dey
Rancher
Posts: 1812
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try RequestDispatcher.forward instead of response.sendRedirect("ProvaCrosshair.jsp");

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A redirect creates a new request, so any scoped variables placed on the request are lost when that happens. A forward transfers the same request from the servlet to the JSP.

You might want to read this article for info on how to properly structure a modern Java web app.

As you are using the session, something else may be in play here.

By the way, why are you using the session?
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!