replay challenge
[Logo] JavaRanch » JavaRanch Saloon
  Search | FAQ | Recent Topics | Hot Topics
Register / Login


Win a copy of JBoss AS 5 Development this week in the JBoss forum
or Spring Dynamic Modules in Action in the Spring forum!
Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » JSP
 
RSS feed
 
New topic
Author

using JSTL and EL to get/set request parameters

Shashank Rudra
Ranch Hand

Joined: Mar 26, 2009
Messages: 131

Hi guys

I am trying to set List as a request parameter in one JSP and then display the same list using EL on other JSP to which I am posting from the first JSP.

The first JSPHere I am setting the request parameter and then submitting to the testList.jsp where I am trying to access the List entries.
testList.jspBut this is getting me this error Please suggest what I need to do differently. TIA

This message was edited 2 times. Last update was at by Giffy Geraldo


Programmer Analyst || J2EE web development/design
Shailesh Narkhede
Ranch Hand

Joined: Jul 10, 2008
Messages: 235

Are you pasted whole jsps?
In testList.jsp we need to put taglib directive to use core jstl tag library.
(you are using c: forEach & c: out)

SCJP 1.4.
SCWCD 1.5
Shashank Rudra
Ranch Hand

Joined: Mar 26, 2009
Messages: 131

I have edited the above post to include those parts that I had just left out. I further found that jar files were missing. So I added jstl-1.2.jar and javax.el.jar.

After this we need javax.servlet.jsp.PageContext.getELContext()Ljavax/el/ELContext. And this is in javaee.jar. When I am trying to add this jar in buildpath - it contains a servlet.class which is creating some conflict.

How to get rid of this.

This message was edited 1 time. Last update was at by Giffy Geraldo


Programmer Analyst || J2EE web development/design
Shailesh Narkhede
Ranch Hand

Joined: Jul 10, 2008
Messages: 235

Which JSP version you are using?
Which container you are using?

SCJP 1.4.
SCWCD 1.5
Shashank Rudra
Ranch Hand

Joined: Mar 26, 2009
Messages: 131

how to see the JSP version? However the web.xml I am using has this DTD declaration Container is Tomcat5.0

This message was edited 1 time. Last update was at by Giffy Geraldo


Programmer Analyst || J2EE web development/design
Shailesh Narkhede
Ranch Hand

Joined: Jul 10, 2008
Messages: 235

Are you included jstl.jar & standard.jar in your web all lib directory?
That is needed for JSTL.

SCJP 1.4.
SCWCD 1.5
Shailesh Narkhede
Ranch Hand

Joined: Jul 10, 2008
Messages: 235

Please check THIS link.
Here you get information regarding configuration for JSTL usage.

SCJP 1.4.
SCWCD 1.5
Shashank Rudra
Ranch Hand

Joined: Mar 26, 2009
Messages: 131

not needed so deleted

This message was edited 1 time. Last update was at by Giffy Geraldo


Programmer Analyst || J2EE web development/design
Shailesh Narkhede
Ranch Hand

Joined: Jul 10, 2008
Messages: 235


I have edited the above post to include those parts that I had just left out. I further found that jar files were missing. So I added jstl-1.2.jar and javax.el.jar.




Are you added jstl-1.2.jar this jar this is for JSP 2.1 (for tomcat 6).
Use jstl.jar with standard.jar you will info about that http://jakarta.apache.org/taglibs/doc/standard-doc/intro.html

SCJP 1.4.
SCWCD 1.5
Shashank Rudra
Ranch Hand

Joined: Mar 26, 2009
Messages: 131

Thanks buddy. Phew
Please check THIS link.
Here you get information regarding configuration for JSTL usage.
did the magic. Now only two jars jstl.jar and standard.jar are doing all the work. No need to go for other jars.

One more thing though- in the second jsp where I am trying to access the List is not working. Please tell me how to get it rite. Also how to know which JSP version I am using. Tomcat5.0 is JSP2.0 container that I just saw in the link but any other way to get at that piece.


Programmer Analyst || J2EE web development/design
Shailesh Narkhede
Ranch Hand

Joined: Jul 10, 2008
Messages: 235

For spacification you ask to container vendor for which JSP version it is supporting.

SCJP 1.4.
SCWCD 1.5
Shashank Rudra
Ranch Hand

Joined: Mar 26, 2009
Messages: 131

I got you. It was really conceptual. But how to access the List set as request parameter and iterate through that. ?? Help me out.

Programmer Analyst || J2EE web development/design
Shailesh Narkhede
Ranch Hand

Joined: Jul 10, 2008
Messages: 235

there is no problem with forEach tag of JSTL.
But through scriptlet also we are not getting ArrayList in testList.jsp.

SCJP 1.4.
SCWCD 1.5
Shashank Rudra
Ranch Hand

Joined: Mar 26, 2009
Messages: 131

When I did I shall be able to get the same attribute using get for the name "strList".

But when I am using in the scriptlets on debugging the file the strList here is coming null. Why is this happening. Has it to take with the serialization aspect of the List. May be List can not be set as attribute in the request. Then how else can we access the collections being returned from a servlet in a JSP page.

Programmer Analyst || J2EE web development/design
David Newton
Author
Bartender

Joined: Sep 29, 2008
Messages: 5591

You're posting a form, thus creating a new request: the current request's attributes aren't available in the new request.

Consultant/Trainer | Polyglottal Developer | Struts Committer/PMC | Struts 2 Web Application Development
Shashank Rudra
Ranch Hand

Joined: Mar 26, 2009
Messages: 131

Very truly pointed out. I added these lines in the first JSP inside the form . This got me the result I was expecting i.e. on the second JSP I am able to access the List elements. Only thing is that while doing cut - the entries are covered by '[' at the start and ']' at the end. I dun kno why?

Thank guys a lot. Without such an active help I would have once again left this exercise incomplete like before.

This message was edited 1 time. Last update was at by Giffy Geraldo


Programmer Analyst || J2EE web development/design
David Newton
Author
Bartender

Joined: Sep 29, 2008
Messages: 5591

Because you're not passing a list, you're passing the string representation of a list.

Forms submit strings--*always*.

Consultant/Trainer | Polyglottal Developer | Struts Committer/PMC | Struts 2 Web Application Development
Shashank Rudra
Ranch Hand

Joined: Mar 26, 2009
Messages: 131

Any way to do as a List?

Here is the code for the above bracket appearance and their removal I bet there is a better way to do this. If any one knows that. TIA

Programmer Analyst || J2EE web development/design
David Newton
Author
Bartender

Joined: Sep 29, 2008
Messages: 5591

If the list is being generated on the business side then either re-generate it, cache it, keep it static, or something. Or just keep it in the session if it's user-specific, or application context if it's app-wide.

Consultant/Trainer | Polyglottal Developer | Struts Committer/PMC | Struts 2 Web Application Development
Bear Bibeault
Author and opinionated walrus
Sheriff

Joined: Jan 10, 2002
Messages: 35625

"Giffy Geraldo", please check your private messages for an important administrative matter.

[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Shashank Rudra
Ranch Hand

Joined: Mar 26, 2009
Messages: 131

Thanks David. That made perfect sense.

Bear, I have done that. Thank you.

This message was edited 1 time. Last update was at by Greg Giraldo


Programmer Analyst || J2EE web development/design
 
 
 
Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » JSP
 
RSS feed
 
New topic
replay challenge