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

Why we shouldn't/can't pick request parameters passed from client inside jsp?

 
Vineet Kumar Garg
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After forwarding a request to a jsp from controller servlet
--- Why we shouldn't/can't pick request parameters passed from client inside jsp?
- why it's recommended to have the data set as attributes and then use it in JSP?



 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64838
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vineet Kumar Garg wrote:After forwarding a request to a jsp from controller servlet
--- Why we shouldn't/can't pick request parameters passed from client inside jsp?

It depends if the same submitted request is being used. If so, then the parameters are still present. If you are using the PRG pattern, which is almost always appropriate, then the parameters are no longer present.

- why it's recommended to have the data set as attributes and then use it in JSP?

Again it depends on the data. Scoped variables (what you are calling attributes) are the most versatile way to convey data from the controller to the JSP.

Perhaps you should give this article a read.
 
Vineet Kumar Garg
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I played a bit more with JSP and found out that all JSP parameters are visible inside jsp as well as it was same object passed from servlet. ( makes sense.)

Now only question is about best practice .. why we shouldn't use parameters from request object inside jsp?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64838
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In some case it may be just fine to.

It's not necessarily a bad practice in itself, but why you may have heard that it's not a good practice is because it may be the result of following something that is a bad practice: submitting a form to a JSP rather than a task controller.

See the article I linked to for more information.
 
Vineet Kumar Garg
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bear. Really nice article.
I got the idea. Will be pinging you more on the way to certification of OCEJWCD :)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic