Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP Expression

 
shiva rao
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is my Jsp source.

<html>
<body>
<%!
String text="Welcome to Expression language";
%>
Welcome to the jsp programming.
<br/>
<strong>If you see this page, it means jsp are also funtioning properly.</strong>
Text = ${text}
</body>
</html>

When I deploy this jsp on tomcat server. For some reason expression ${text} is not replaced with the text Instead I am just seeing ${text} as is was.

Expected output for the expression part is :
-----------------------------------
Text = Welcome to Expression language
-------------------------------------

Did I miss something here.

Thanks!!

Shiva
[ November 22, 2005: Message edited by: shiva rao ]
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Did I miss something here."

Yes, the correct forum. Moving to JSP...
 
Derek Clarkson
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmm, you might want to check the server versions you are on and what JSTL and EL they support. Without checking myself, I remember reading that only the very latest spec versions support using ${test} inside the html in this manner. Previous versions of the spec do not support this and you will need to use



Instead. Check up on the JSTL tags and how to use them.
[ November 22, 2005: Message edited by: Derek Clarkson ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64633
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What version of Tomcat? Is your web app declared as a Servlet 2.4 web app? (See JSP FAQ)

The fact that the EL expression is not being evaluated means that the EL is not enabled. You must be using a JSP 2.0 container (Tomcat 5) and the web app must be declared as 2.4.

But....

once the EL is enabled you will fnd that this does not do what you expect.

The variable text is a scripting variable, while the EL operates upon scoped variables.
[ November 22, 2005: Message edited by: Bear Bibeault ]
 
shiva rao
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for the reply. Here are the server details:

I am using Tomcat 5.5 and it supports JSP 2.0.
Here are the common jars it is refering to .

commons-el.jar
jasper-compiler-jdt.jar
jasper-compiler.jar
jasper-runtime.jar
jsp-api.jar
naming-factory-dbcp.jar
naming-factory.jar
naming-resources.jar
servlet-api.jar

And can you guys tell me how do I know whether server enabled or disabled the EL. And also where can I do that.

Thanks.
Shiva
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64633
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is an entry in the JSP FAQ.
 
Bosun Bello
Ranch Hand
Posts: 1510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As posted above, make sure the top of your DD is defined as using 2.4 as below
-------------------------------------------------
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic