aspose file tools*
The moose likes JSP and the fly likes Is submitting a form send-redirect or forward? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Is submitting a form send-redirect or forward?" Watch "Is submitting a form send-redirect or forward?" New topic
Author

Is submitting a form send-redirect or forward?

Suvojyoty Saha
Greenhorn

Joined: Apr 19, 2011
Posts: 25

When we submit a form of a *.jsp file does it act as a send re-direct?

For example:

The following code is a part of the jsp file

I'm trying to set a request attribute so that when the control reaches my servlet i can use it for my own purpose. But on trying to retrieve the attribute and set it some where else i'm getting a NullPointer Exception. Is this because on submit the action taking place is send-redirect instead of forward?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

When the user clicks on the Submit button in that form in the browser, it submits a request to your server. That is neither a redirect nor a forward, those are actions which your code may do on the server.

But if you were assuming the request which ran that JSP and generated the HTML containing that form would be the same as the request which later came from the browser when the user clicked the Submit button, that was an incorrect assumption. That isn't how it works. Your JSP generates HTML which is sent to the browser. Later the user may click on controls in that HTML which generate requests.
Suvojyoty Saha
Greenhorn

Joined: Apr 19, 2011
Posts: 25

Thanks Paul I think I understand what you are saying. What I'm trying to do can be easily accomplished using Hidden Field as it would contain the data that would be passed from the browser to the server.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61010
    
  65

You could also use a session-scoped variable.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Suvojyoty Saha
Greenhorn

Joined: Apr 19, 2011
Posts: 25

Thanks Bear I'm planing to use sessions soon as a login page needs to invoke sessions. Thanks a lot once again.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Is submitting a form send-redirect or forward?