Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP to JSP Forward to Servlet

 
Timothy Sam
Ranch Hand
Posts: 751
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I have a JSP that forwards to itself for validation. Then it forwards to a servlet for further processing... I was wondering... Wouldn't I lose my post data? Is there any solution to this? Thanks!
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64851
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was wondering... Wouldn't I lose my post data?


Have you verified this?
 
Timothy Sam
Ranch Hand
Posts: 751
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bear
I just tried what I was trying to say... And yes it displayed null...

System.out.println(request.getParameter("firstname")) displayed null... I used response.sendRedirect("/mypackage/myservlet"). Thanks!
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64851
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your first post you say you are forwarding. In your second you say you are redirecting. They are not the same and they act very differently.

So which is it?

A forward passes the current request along to a new resource. Request parameters and scoped variable are therefore preserved.

A redirect causes a new request to be issued by the browser. Hence request parameters and scoped variables are not preserved.
[ October 26, 2005: Message edited by: Bear Bibeault ]
 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does this include Context attributes too. Because I tried setting a context attribute in Servlet used sendRedirect and got the expected result in Jsp page. But If I include a request attribute then both context and request attributes are null in Jsp. Why is this happening?
 
MInu
Ranch Hand
Posts: 517
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
store your data in session.
 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got the answer. I don't know why that behaved in that way. But now I am getting context attributes in Jsp page and request attributes as null. Since context attributes are avavialbe for the whole application there will not be a ny issue over that.

Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic