aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes doubt in EL 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 » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "doubt in EL" Watch "doubt in EL" New topic
Author

doubt in EL

raja ram
Ranch Hand

Joined: Mar 02, 2008
Posts: 169
Hi,

I have the following code in the servlet

List ol=new ArrayList();
ol.add("hi");
ol.add("this");
RequestDispatcher rd=request.getRequestDispatcher("/jsp/testEL.jsp");
rd.forward(request,response);

and below code in the testEL.jsp

Values from the List are :${list["0"]} ${list["1"]}

but instead of getting the "hi this" as the out put i get "Values from the List are :${list["0"]} ${list["1"]}"
as the output the EL is not getting evaluated.

Is there any specific setup that i need to do for this to work.

Thanks
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

please

add this in your servlet

request.setAttribute("list_name",list);

and in jsp

${list_name["0"]} or ${list_name[0]}
thanks & regards,
seetharaman
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Or without touching the JSP :


Also make sure that you have configured everything properly. Check this FAQ.
[ May 12, 2008: Message edited by: Christophe Verre ]

[My Blog]
All roads lead to JavaRanch
raja ram
Ranch Hand

Joined: Mar 02, 2008
Posts: 169
Hi,

Sorry I have already put the code in my servlet i didnt show it here
request.setAttribute("list",ol);

Thanks
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Ok then All left to do is to check the FAQ I have posted above. Make sure your web.xml is declared correctly.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Hi rajaram,

add isELIgnored="false"(but it is default behaviour) in your page directory of jsp...whether you put isELIgnored="true" like anything?

thanks & regards,
seetharaman
raja ram
Ranch Hand

Joined: Mar 02, 2008
Posts: 169
Hi,

I have added following entry in the web.xml file

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">


<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">

Thanks
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Remove the DOCTYPE and do an exact copy/paste of the one written here.
raja ram
Ranch Hand

Joined: Mar 02, 2008
Posts: 169
Hi,

I deleted the DOC Type and did a exact copy paste of the specified contents like below

<?xml version="1.0" encoding="UTF-8"?>


<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">

i tried it with both the tags specified in that link but still it didnt work
I am using tomcat Apache Tomcat/5.0.28 what could be the problem.

can any body give me a working web.xml file for EL
Thanks
[ May 12, 2008: Message edited by: raja ram ]
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Remove also the first line Leave only the web-app tag.
raja ram
Ranch Hand

Joined: Mar 02, 2008
Posts: 169
Yes I removed the first line and kept only <web-app> even then no results.

Thanks
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Can you post the web.xml you now have ? And also please tell us where you put web.xml.

One more thing. You are using Tomcat 5.0.x. I recommend you to use Tomcat 5.5.x instead (although they are supposed to support the same spec...)
raja ram
Ranch Hand

Joined: Mar 02, 2008
Posts: 169
Hi,
My web.xml file contains the following


and web.xml file is present in this Path "C:\tomcat\webapps\learn\WEB-INF\web.xml"

Thanks
Nishal Dsouza
Greenhorn

Joined: Dec 02, 2007
Posts: 18
Can you tell me which container and which version are you using?


Nishal Allan Dsouza<br /> <br />SCJP 5,SCWCD 5
raja ram
Ranch Hand

Joined: Mar 02, 2008
Posts: 169
Apache Tomcat/5.0.28
Garlapati Ravi
Ranch Hand

Joined: Mar 05, 2008
Posts: 171
do you have this line in you JSP ?


Ravi Kumar
SCWCD 5 - 89%, SCJP 1.4 - 90%
S Sravs
Ranch Hand

Joined: Feb 25, 2008
Posts: 85
check if you have proper jar files
standard.jar and jstl.jar

Regards
Sravanthi
Nishal Dsouza
Greenhorn

Joined: Dec 02, 2007
Posts: 18
install tomcat 5.5.26 or higher version it should work
Nishal Dsouza
Greenhorn

Joined: Dec 02, 2007
Posts: 18
This is because the container you are using does not support EL because it implements lower versions of JSP 2.0 specification.
raja ram
Ranch Hand

Joined: Mar 02, 2008
Posts: 169
Hi,

I have installed Apache Tomcat/5.5.26 now and tried with the same code but i am getting this exception

javax.servlet.ServletException: javax.servlet.jsp.PageContext.getVariableResolver()Ljavax/servlet/jsp/el/VariableResolver;
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:841)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:774)
org.apache.jsp.jsp.testEL_jsp._jspService(testEL_jsp.java:69)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
com.scwcd.TestEl.doGet(TestEl.java:27)
javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

I have also copied jstl.jar and standard.jar files to my WEB-INF\lib folder
Thanks
S Sravs
Ranch Hand

Joined: Feb 25, 2008
Posts: 85
even tough Tommcat has inbuilt el-api.jar file and jasper-el.jar files add into your lib path and restart
hope this solves your problem

Reagards
Sravanthi
John Pearson
Ranch Hand

Joined: Oct 19, 2007
Posts: 51
I couldn't see any obvious problem, so I wrote a quick test app to try it, using your servlet code, jsp, and web.xml. It all worked fine! it produced the output:


Since the exception seems to be coming from VariableResolver, I'd check your JSP code very carefully to make sure you don't have any typos that might be causing it to choke when it tries to evaluate "${list["0"]} ${list["1"]}".
Garlapati Ravi
Ranch Hand

Joined: Mar 05, 2008
Posts: 171
what is the java version you are using ? is it below 1.4 ?
John Stone
Ranch Hand

Joined: May 04, 2007
Posts: 332
Also delete \apache-tomcat-6.0.14\work\Catalina\localhost\YOUR_WEB_APP.
I had the same problem, read the faq, tried multiple web.xml's and all I got was ${1+1}, I deleted classes from tomcat's work dir and it started to work :-).

EDIT: I suggest to add this to FAQ.
[ May 14, 2008: Message edited by: John Stone ]
S Sravs
Ranch Hand

Joined: Feb 25, 2008
Posts: 85
Hi Sourabh Gandhi,
thanks for the link

Regards
Sravanthi
preparing for wcd 1.5
raja ram
Ranch Hand

Joined: Mar 02, 2008
Posts: 169
Hi,

Any solution to this problem all this time i am thinking that there is a problem with my code only but even the JSTL exapmles that come along with the tomcat is also giving the same error. what could be the reason
I am using
Apache Tomcat/5.5.26 conatiner and JDK 1.5

Thanks
Ash More'
Ranch Hand

Joined: Apr 20, 2008
Posts: 47
hi raja ram,
have you tried what Vijaya said a few posts back? have you added el-api.jar file to your class-path. i think that file is available in tomcat 6 in the lib directory.(or if you have jboss available to you, its in the C:\JBoss\jboss-4.2.0.GA\server\default\lib directory ). Also add this to the classpath: servlet-api.jar and jsp-api.jar

Restart tomcat and try out the tomcat examples.
raja ram
Ranch Hand

Joined: Mar 02, 2008
Posts: 169
Hi,

The problem is resolved i copied jsp-api.jar and servlet-api.jar in the
C:\tomcat\common\endorsed directory and restart the server it works fine now.

Thanks for all the replies
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: doubt in EL