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 Couple of questions on JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Couple of questions on JSP" Watch "Couple of questions on JSP" New topic
Author

Couple of questions on JSP

Rajesh Khan
Ranch Hand

Joined: Oct 16, 2011
Posts: 230
Hi i wanted to know how you could create an arraylists on a JSP without using scriptlets.
I actually wanted to do something like this but without using Scriptlets..



so the questions are
1)Request is an implicit object passed to a jsp how could i set a value in the request object using EL ?
2)Can i create an arraylist using JSTL ?? Any hint , example would be appreciated
3) How would i accomplish this using JSTL (does that make sense) or without scriptlets?
RequestDispatcher view=request.getRequestDispatcher("test");
view.forward(request, response);


Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

Rajesh Khan wrote:Hi i wanted to know how you could create an arraylists on a JSP without using scriptlets.

You can't and you shouldn't.

JSPs for for generating the view. Any such structures should be created prior to forwarding to the JSP in its controller.

If for some rare reason the creation must take place under control of the JSP, then a custom tag or EL function can be used.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

Rajesh Khan wrote:
1)Request is an implicit object passed to a jsp how could i set a value in the request object using EL ?

The request is available in the pageContext.

2)Can i create an arraylist using JSTL ?? Any hint , example would be appreciated

No, see above reply. There are lots of things that aren't easy to do in a JSP by design because you shouldn't be doing those sorts of things there.

3) How would i accomplish this using JSTL (does that make sense) or without scriptlets?

There's a JSP action for that -- but note that it's rare to have to forward from a JSP and it's almost always a red flag that your design is likely flawed.
Miku Ranjan
Ranch Hand

Joined: Oct 11, 2011
Posts: 98
Hi,
you can set array list in request as attribute and iterate it in it forwarded jsp using EL.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Couple of questions on JSP