aspose file tools*
The moose likes JSP and the fly likes creating a map using JSTL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "creating a map using JSTL" Watch "creating a map using JSTL" New topic
Author

creating a map using JSTL

Niranjan PY Prasad
Greenhorn

Joined: Jun 29, 2006
Posts: 2
Hi folks i want to create a map using only JSTL and want to set key and value to that map. and also want to retrive the values in that map.

I only want to use JSTL.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61230
    
  66

The JSTL and EL are primarily intended to consume data rather than create it, so their ability to do so is quite limited.

For example, you cannot create a new object instance.

It's customary to create the data instances in the servlet controller prior to forwarding to the JSP.
[ March 20, 2007: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Niranjan PY Prasad
Greenhorn

Joined: Jun 29, 2006
Posts: 2
Thanks for the reply Bear,

is there any way to create a map using <c:set /> ?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

No.
If you need to do this, you're probably not using JSTL properly.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Tim Cor
Greenhorn

Joined: Sep 22, 2011
Posts: 1
Niranjan PY Prasad wrote:Hi folks i want to create a map using only JSTL and want to set key and value to that map. and also want to retrive the values in that map.

I only want to use JSTL.


Per Lindberg
Ranch Hand

Joined: Jan 17, 2008
Posts: 48
And if you're not so strict about using only JSTL:

This example creates a Map specifying columns to hide (later).

It has the advantage that it can be included several times in the same JSP, since jspUseBean does not tolerate duplicate id:s.
(Another way might be to use a JSP tag file).

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61230
    
  66

Mixing scriptlets into the JSP along with JSTL and EL is a big old mess. I would not recommend this.
Per Lindberg
Ranch Hand

Joined: Jan 17, 2008
Posts: 48
Agreed. Hiding the the bean in e.g. tag context would be cleaner.
And, of course, if you only need one instance, then jsp:useBean is The Right Thing.
Any other neat alternatives?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61230
    
  66

I'd just create it in the page controller like anything else needed for the page.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: creating a map using JSTL