What's wrong with this code?

The following JSP uses EL(Expression Lenguage) it's supposed to bring up a page that says Hello with a text field for you to put your name in, and when you click submit query it's supposed to say Hello "name" but when you start it it says Hello with the expression to get the name in front, and doesnt do anything when you try placing a name

The code is from the book "Pro JSP 2" Chapter 3, it is written as is and can be seen in the following link

http://www.apress.com/ApressCorporate/supplement/1/464/1590595130-3221.pdf

templateText.jsp

<html>

<head>

<title>EL and Template Text</title>

<style>

body,td {font-family:verdana,;}

</style>

</head>

<body>

<h2>EL and Template Text</h2>

<table border="1">

<tr>

<td colspan="2">Hello ${param['name']}</td>

</tr>

<tr>

<form action="templateText.jsp" method="post">

<td><input type="text" name="name"></td>

<td><input type="submit"></td>

</form>

</tr>

</table>

</body>

</html>

How can I get it to work? Thanks in advanced...

[1318 byte] By [Esizkura] at [2007-10-3 1:33:52]
# 1

2 probable causes

1. You arent using a container that supports expression language in jsp. Please note that EL support (outside of the jstl tags) were introduced only in the j2ee 1.4 (servlet 2.4/ jsp 2.0) spec. So you need such a compliant container (Tomcat 5.0 and aboce does support, fyi).

2. You are using a servlet 2.4 container, but your web application itself doesnt conform to the 2.4 spec. (you can deploy a 2.3 web application in a 2.4 container).

If that is the case, specify that your web application is 2.4 compliant by this schema definition in your web.xml

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

//other elements

</web-app>

A couple of side notes.

1. Please use the [ code ] tags (without the space) while posting code. Read about formatting tips [url http://forum.java.sun.com/help.jspa?sec=formatting]here[/url]

2. Please use a more specific subject line - it'll help others in their search for solutions when they face the same issue.

ram.

Madathil_Prasada at 2007-7-14 18:31:51 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Are you running the page through your web server, i.e.

http://localhost/yourApplicationName/templateText.jsp

You cannot simply view these pages in a browser.

If you webserver is ok, then the problem is with your tags, check all opening and closing tags are correct. I had a quick look and they seem ok to me.

angrycata at 2007-7-14 18:31:51 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
I got it to work by adding<%@ page isELIgnored="false" %>but according to the book EL is enabled by default on 2.5 XML Schema, is there anything I should do or check?
Esizkura at 2007-7-14 18:31:51 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

I'm using Tomcat 5.5

my web.xml

xmlns="http://java.sun.com/xml/ns/javaee"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd

version="2.5"

I'm running from localhost, but for some reason EL is disabled...

Esizkura at 2007-7-14 18:31:51 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

In 2.3 you would have needed to do that as EL is ignored by default - so if your container supports it and you are using a 2.3 web application, you would setisELIgnored=false as a quick workaround.

In 2.4 you dont need to do that, I havent got to 2.5 yet, so I cant say. 2.5 is pretty new and support may be scratchy. Why dont you stick to 2.4? And which server are you using. Its interesting as I thought the implementations of 2.5 were yet to hit the market.

ram.

Madathil_Prasada at 2007-7-14 18:31:51 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

Thanks!!

Well I tried with 2.4 and it works perfectly...

The thing I don't know is in the book it says it is also on by default on 2.5...

The xsi:schemaLocation is "http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" but I noticed that in the 2.4 instead of javaee it's j2ee

so I replaced javaee for j2ee, and left the 2.5 version and it works... so is it possible it is actually j2ee/web-app_2_5.xsd and not javaee/web-app_2_5.xsd or is it just a coincidence it worked...?

Esizkura at 2007-7-14 18:31:51 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7

> Thanks!!

>

> Well I tried with 2.4 and it works perfectly...

>

> The thing I don't know is in the book it says it is

> also on by default on 2.5...

Yes it should be - no doubt about that - they are hardly going to take a step backwards into 2.3 age :)

>

> The xsi:schemaLocation is

> "http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"

> but I noticed that in the 2.4 instead of javaee it's

> j2ee

>

> so I replaced javaee for j2ee, and left the 2.5

> version and it works... so is it possible it is

> actually j2ee/web-app_2_5.xsd and not

> javaee/web-app_2_5.xsd or is it just a coincidence it

> worked...?

I would say scratchy implementation.

Type http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd

in your browser - you would actually get the schema displayed

Then type http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd

and you would get an error page suggesting that the former is correct.

And anyways the 2.5 implementation belongs to the java EE 5 version of enterprise java (no more j2ee).

How I hate sun's java versioning schemes. Glad you got it to work. I would suggest that you stick to the stable 2.4 version though - you'll have less of such headaches to contend with.

cheers,

ram.

Madathil_Prasada at 2007-7-14 18:31:51 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8
Well, I'll stick to 2.4 for now, thanks for all the help!!Good luck...
Esizkura at 2007-7-14 18:31:51 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...