aspose file tools*
The moose likes Servlets and the fly likes JSP to JSP Forward to Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "JSP to JSP Forward to Servlet" Watch "JSP to JSP Forward to Servlet" New topic
Author

JSP to JSP Forward to Servlet

Timothy Sam
Ranch Hand

Joined: Sep 18, 2005
Posts: 746
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!


SCJP 1.5
http://devpinoy.org/blogs/lamia/ - http://everypesocounts.com/
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61202
    
  66

I was wondering... Wouldn't I lose my post data?


Have you verified this?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Timothy Sam
Ranch Hand

Joined: Sep 18, 2005
Posts: 746
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

Joined: Jan 10, 2002
Posts: 61202
    
  66

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

Joined: Nov 15, 2004
Posts: 1026
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?


Servlet Spec 2.4/ Jsp Spec 2.0/ JSTL Spec 1.1 - JSTL Tag Documentation
MInu
Ranch Hand

Joined: Oct 09, 2003
Posts: 517
store your data in session.


God Gave Me Nothing I Wanted<br />He Gave Me Everything I Needed<br /> - Swami Vivekananda
Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP to JSP Forward to Servlet