This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSTL problem: Can't access collection

 
Daniel Zuckermann
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65110
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hint: your test is incorrect.
 
Daniel Zuckermann
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I actually wanted to achive is this, but this doesn't work also:
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65110
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65110
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65110
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65110
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65110
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic