File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Why we shouldn't/can't pick request parameters passed from client inside jsp? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Why we shouldn Watch "Why we shouldn New topic
Author

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

Vineet Kumar Garg
Greenhorn

Joined: Apr 11, 2012
Posts: 21
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

Joined: Jan 10, 2002
Posts: 61413
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Vineet Kumar Garg
Greenhorn

Joined: Apr 11, 2012
Posts: 21
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

Joined: Jan 10, 2002
Posts: 61413
    
  67

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

Joined: Apr 11, 2012
Posts: 21
Thanks Bear. Really nice article.
I got the idea. Will be pinging you more on the way to certification of OCEJWCD :)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why we shouldn't/can't pick request parameters passed from client inside jsp?