Two Laptop Bag*
The moose likes JSP and the fly likes Expression Language Doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Expression Language Doubt" Watch "Expression Language Doubt" New topic
Author

Expression Language Doubt

george vasanth
Greenhorn

Joined: Jul 07, 2004
Posts: 19
Hi,

I was trying out my hand in Expression Language. I had the following code in my servlet.

request.setAttribute("music","A.R.Rahman");

I tried to retrive the variable music from JSP using Expression Language.

Following is my JSP code:

<html><body>
Music is: ${music}
</html></body>

But this is what that got dispalyed

Music is: ${music}

But if i use a tag library along with the EL i was able to get the desired result.

<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<html><body>
Music is: <c ut value="${music}"/>
</html></body>

This displayed as follows:

Music is:A.R.Rahman

I would like to know what is the problem when using EL alone. I am using Tomacat 5.5.12 with JDK5.0. I have included the jstl.jar and statndard.jar in common/lib folder for JSTL

I think by default the EL is on. I even switched it on through web.xml but still it did not work.

Could any one help me out in this please.

Thanks in advance
Balaji
Prasad Yarehalli
Greenhorn

Joined: Dec 08, 2005
Posts: 12
What version of JSP and SERVLETS are you using? I think you should use JSP 2.0 and servlet 2.4 to make this work.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60776
    
  65

Originally posted by george vasanth:
I think by default the EL is on. I even switched it on through web.xml but still it did not work.


How did you switch it on in web.xml? Check this JSP FAQ for how your web app should be declared.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
george vasanth
Greenhorn

Joined: Jul 07, 2004
Posts: 19
Hi,

I think i am using JSP version 2.0 and servlet 2.4, as i thought since i am using Tomcat version 5 which does suppport JSP 2.0 and servlet 2.4, i could use the EL which is in JSP 2.0 spec.
Prasad Yarehalli
Greenhorn

Joined: Dec 08, 2005
Posts: 12
What you are trying to do is new thing and is only available in JSP 2.0
george vasanth
Greenhorn

Joined: Jul 07, 2004
Posts: 19
I switched on EL like this:

<jsp-property-group>
<description>
Special property group for JSP Configuration JSP example.
</description>
<el-ignored>false</el-ignored>
</jsp-property-group>

By default it is false. I tried even giving it explicitly...
george vasanth
Greenhorn

Joined: Jul 07, 2004
Posts: 19
Yes i know EL is new to JSP but TOMCAT 5.0 is supporting JSP 2.0 right. So EL should work in Tomcat 5.0 i am not sure why it is not working. I think the webserver is not interpreting the EL.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60776
    
  65

Did you read my reply? Tomcat 5 only "turns on" the EL for web apps declared as Servlets 2.4 web apps.
Shrinivas Mujumdar
Ranch Hand

Joined: Aug 27, 2004
Posts: 328
Initially You said you are using Tomcat 5.5.12(?..This is not existing) & later on you are saying that you are using Tomcat 5.0...whats exact situation?

Actually I have faced the same issue couple of months back....I have used Tomcat 5.5.7 & it works with that although Apache people are saying that Tomcat 5.0 supports JSP 2.0 EL doesn't work with tomcat 5.0 versions....i don't know why.

I have tried it on almost all tomcat 5.0.x versions with lot of options like changing page directive & making web.xml entries but it worked on Tomcat 5.5.7 & not anywhere else(even in weblogic 6.1 & 8.1 versions)

Shrinivas
ramprasad madathil
Ranch Hand

Joined: Jan 24, 2005
Posts: 489


You said you are using Tomcat 5.5.12(?..This is not existing)


It does.


it works with that although Apache people are saying that Tomcat 5.0 supports JSP 2.0 EL doesn't work with tomcat 5.0 versions....i don't know why.


Look at what Bear has said -

Did you read my reply? Tomcat 5 only "turns on" the EL for web apps declared as Servlets 2.4 web apps.


In short it means that your using Tomcat 5.0 or above is not sufficient, your web app should be servlet 2.4 compliant. You do this via your web.xml schema declaration


not anywhere else(even in weblogic 6.1 & 8.1 versions)

Weblogic upto 8.1 doesnt support servlets 2.4 and jsp 2.0

cheers,
ram.
Shrinivas Mujumdar
Ranch Hand

Joined: Aug 27, 2004
Posts: 328
Tomcat 5.0 Claim

Tomcat version 5 implements the Servlet 2.4 and JavaServer Pages 2.0 specifications from the Java Community Process, and includes many additional features that make it a useful platform for developing and deploying web applications and web services.

On Tomcat 5.0 with lot of Hook & crook also it doesn't work...

Ya i do agree 5.5.12 is existing sorry for that

Whether weblogic 9.0 supports Servlet 2.4?

Shrinivas
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60776
    
  65

Originally posted by Shrinivas Mujumdar:
On Tomcat 5.0 with lot of Hook & crook also it doesn't work...


Bull!

I'm using Tomcat 5.0 and I have no problems with JSP 2.0. Just because you haven't configured it correctly does not mean it doesn't work.
[ January 10, 2006: Message edited by: Bear Bibeault ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Works for me as well.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
george vasanth
Greenhorn

Joined: Jul 07, 2004
Posts: 19
Hi,

I am using Tomact version 5.5.12. Still EL not been interpreted.

In web.xml this is the DTD and web-app tag i am using

<!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">

In the DTD if i change the "DTD Web Application 2.3" and "http://java.sun.com/dtd/web-app_2_3.dtd" as

"DTD Web Application 2.4" and
"http://java.sun.com/dtd/web-app_2_4.dtd"

I am getting the following error when i start the server...

SEVERE: Parse error in application web.xml
java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.<init>(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startEntity(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startDTDEntity(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl.setInputSource(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDispatcher.dispatch(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
at org.apache.tomcat.util.digester.Digester.parse(Digester.java:1561)
at org.apache.catalina.startup.ContextConfig.applicationWebConfig(ContextConfig.java:339)
at org.apache.catalina.startup.ContextConfig.start(ContextConfig.java:1031)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:255)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4076)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:759)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:739)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:524)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:910)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:873)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:474)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1118)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:310)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1020)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:718)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1012)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:442)
at org.apache.catalina.core.StandardService.start(StandardService.java:450)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:680)
at org.apache.catalina.startup.Catalina.start(Catalina.java:536)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:275)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Jan 16, 2006 11:42:23 AM org.apache.catalina.startup.ContextConfig start
SEVERE: Marking this application unavailable due to previous error(s)
Jan 16, 2006 11:42:23 AM org.apache.catalina.core.StandardContext start
SEVERE: Error getConfigured
Jan 16, 2006 11:42:23 AM org.apache.catalina.core.StandardContext start
SEVERE: Context [/SunCert] startup failed due to previous errors

How else should i make sure that Servlet2.4 is been used..

Thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60776
    
  65

See the JSP FAQ for the proper way to declare your app in the web.xml file.
[ January 16, 2006: Message edited by: Bear Bibeault ]
george vasanth
Greenhorn

Joined: Jul 07, 2004
Posts: 19
Below is the web.xml that i have

<?xml version="1.0" encoding="ISO-8859-1"?>
<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">
<servlet>
<servlet-name>ControllerServlet</servlet-name>
<servlet-class>ControllerServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ControllerServlet</servlet-name>
<url-pattern>/servlet/controller</url-pattern>
</servlet-mapping>
<jsp-property-group>
<description>
Special property group for JSP Configuration JSP example.
</description>
<el-ignored>false</el-ignored>
</jsp-property-group>
</web-app>


I tried it exactly the way it was given in the JSP FAQ's
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60776
    
  65

SEVERE: Parse error in application web.xml


You most likely have a syntax error in your web.xml. The 2.4 schema is more particular, especially regarding the order of the elements, than the 2.3 DTD.
george vasanth
Greenhorn

Joined: Jul 07, 2004
Posts: 19
But with the web.xml as above i am not getting any syntax error...
Could u please let me know if there is any problem with the web.xml above
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1016
The <jsp-property-group> tag needs to be nested in a <jsp-config>
ie


However the el-ignored property is false by default, as long as you have specified your web.xml as being version 2.4. You should not need to set this element at all.
If you use the 2.3 DTD declaration, it disables EL for backwards compatibility. Refer to the JSP2.0 specification section 3.3.2 for full details.

Also just in case: your servlet class MUST be in a package. Classes in the default package are no longer accessible (since java 1.4)

ie your web.xml file should just be:


Bear said:

> The 2.4 schema is more particular, especially regarding the order of the elements, than the 2.3 DTD.

Actually I believe the opposite is true. The 2.4 schema relaxes the strict ordering imposed by the 2.3 DTD. You can now intersperse your servlet/servlet-mapping elements logically as opposed to declaring all your servlets followed by all the mappings.

Cheers,
evnafets
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

The easiest way to make sure you have the most up to date deployment descriptor for the version of Tomcat you're using is to copy the one from webpps/ROOT/WEB-INF.

Then remove everything beween the <web-app ...> tag and the </web-app> tag.
Start your app and test with a few real simple JSPs.
Then, if all is well, add your servlet and servlet-mapping entries.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Expression Language Doubt
 
Similar Threads
NoSuchMethodError when usin Tomcat and JSTL
Calling JavaScript using EL
Can we put EL in a for loop?
jstl "expression language ( "${...}" ) in static text
c:forEach