• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is submitting a form send-redirect or forward?

 
Suvojyoty Saha
Greenhorn
Posts: 25
Firefox Browser Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 25
Firefox Browser Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65120
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could also use a session-scoped variable.
 
Suvojyoty Saha
Greenhorn
Posts: 25
Firefox Browser Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bear I'm planing to use sessions soon as a login page needs to invoke sessions. Thanks a lot once again.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic