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

Couple of questions on JSP

 
Rajesh Khan
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64833
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64833
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 98
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
you can set array list in request as attribute and iterate it in it forwarded jsp using EL.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic