wood burning stoves 2.0*
The moose likes JSP and the fly likes using JSTL and EL to get/set request parameters 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 "using JSTL and EL to get/set request parameters" Watch "using JSTL and EL to get/set request parameters" New topic
Author

using JSTL and EL to get/set request parameters

Shashank Rudra
Ranch Hand

Joined: Mar 26, 2009
Posts: 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


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

Joined: Jul 10, 2008
Posts: 368
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)


Thanks,
Shailesh
Shashank Rudra
Ranch Hand

Joined: Mar 26, 2009
Posts: 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.
Shailesh Narkhede
Ranch Hand

Joined: Jul 10, 2008
Posts: 368
Which JSP version you are using?
Which container you are using?
Shashank Rudra
Ranch Hand

Joined: Mar 26, 2009
Posts: 131
how to see the JSP version? However the web.xml I am using has this DTD declaration Container is Tomcat5.0
Shailesh Narkhede
Ranch Hand

Joined: Jul 10, 2008
Posts: 368
Are you included jstl.jar & standard.jar in your web all lib directory?
That is needed for JSTL.
Shailesh Narkhede
Ranch Hand

Joined: Jul 10, 2008
Posts: 368
Please check THIS link.
Here you get information regarding configuration for JSTL usage.
Shashank Rudra
Ranch Hand

Joined: Mar 26, 2009
Posts: 131
not needed so deleted
Shailesh Narkhede
Ranch Hand

Joined: Jul 10, 2008
Posts: 368

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
Shashank Rudra
Ranch Hand

Joined: Mar 26, 2009
Posts: 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.

Shailesh Narkhede
Ranch Hand

Joined: Jul 10, 2008
Posts: 368
For spacification you ask to container vendor for which JSP version it is supporting.
Shashank Rudra
Ranch Hand

Joined: Mar 26, 2009
Posts: 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.
Shailesh Narkhede
Ranch Hand

Joined: Jul 10, 2008
Posts: 368
there is no problem with forEach tag of JSTL.
But through scriptlet also we are not getting ArrayList in testList.jsp.
Shashank Rudra
Ranch Hand

Joined: Mar 26, 2009
Posts: 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.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Mar 26, 2009
Posts: 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.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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

Forms submit strings--*always*.
Shashank Rudra
Ranch Hand

Joined: Mar 26, 2009
Posts: 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
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61426
    
  67

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


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Shashank Rudra
Ranch Hand

Joined: Mar 26, 2009
Posts: 131
Thanks David. That made perfect sense.

Bear, I have done that. Thank you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: using JSTL and EL to get/set request parameters