aspose file tools*
The moose likes JSP and the fly likes JSTL problem: Can't access collection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "JSTL problem: Can Watch "JSTL problem: Can New topic
Author

JSTL problem: Can't access collection

Daniel Zuckermann
Ranch Hand

Joined: May 14, 2012
Posts: 50
I have some data, that is read from a collection and then displayed:


But when I check if the collection is available, I don't get any output:
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61413
    
  67

Hint: your test is incorrect.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Daniel Zuckermann
Ranch Hand

Joined: May 14, 2012
Posts: 50
What I actually wanted to achive is this, but this doesn't work also:
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61413
    
  67

Daniel Zuckermann wrote:What I actually wanted to achive is this, but this doesn't work also:

Please read ItDoesntWorkIsUseless

What exactly is the scoped variable person?
Daniel Zuckermann
Ranch Hand

Joined: May 14, 2012
Posts: 50
In the request object is an object that contains a collection which is called "person". The attributes of the elements that are contained in the collection should be read.

It works this way:


I tried to accomplish the same with a JSTL loop, but I don't get any output. Even simple JSTL tags don't produce output.

Here is the page declaration of the jsp page:


and here the declatation in the web.xml:
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61413
    
  67

Daniel Zuckermann wrote:In the request object is an object that contains a collection which is called "person".

Then what is DataObj? If person is in request scope, why aren't you just using "person"?

You also never answered my question. What is person? "a collection" is not helpful. What type of collection? List? Map? array? And a collection of what?

Even simple JSTL tags don't produce output.

Well of course if you don't have the JSTL enabled, nothing using the JSTL is going to work. You need to fix that first before worrying about anything else.

Does <c:out value="${3+4}"/> render to 7? If not, getting that to work is step 1 and everything else is just a red herring.
Daniel Zuckermann
Ranch Hand

Joined: May 14, 2012
Posts: 50
No, it doesn't render anything. I think there something wrong in my declaration. The person-attribute is a Vector.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61413
    
  67

Not anything? What's sent to the browser? Please be specific.

Have you followed the instructions in the JspFaq for setting up the JSTL?
Daniel Zuckermann
Ranch Hand

Joined: May 14, 2012
Posts: 50
No, I don't get any JSTL output. I have two files in my WEB-INF/lib folder: javax.servlet.jsp.jstl-1.2.1.jar and javax.servlet.jsp.jstl-api-1.2.1.jar.
Daniel Zuckermann
Ranch Hand

Joined: May 14, 2012
Posts: 50
I fixed the problem. It was caused by the jsp page. For whatever reason it works with this declaration

but it didn't work with the declaration I have posted before.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61413
    
  67

Daniel Zuckermann wrote:I fixed the problem. It was caused by the jsp page. For whatever reason it works with this declaration ...


Which one are you talking about? There are three there.

If you are talking about the taglib declaration, then yes, you must declare a tag lib before using it.

And what's with the XML declaration? Why is that there?
Daniel Zuckermann
Ranch Hand

Joined: May 14, 2012
Posts: 50
At first I selected the jsp template "jsp with jsp 2.0 specific tags, xhtml markup and xml style syntax". However, this didn't work.

Then I changed the file to this:


This works, but I still don't know why.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61413
    
  67

Remove all but the tag lib declaration. The XML declaration is wrong, and the page directive is specifying poor choices. The defaults are fine.

All that you need to enable the core JSTL tags is the taglib declaration. How did you expect the taglib to work if you didn't declare it?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSTL problem: Can't access collection