Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EL Again!

 
pallavi utukuri
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
installed Tomcat5.0
created Testj.java in
D:\tomcat5.0\webapps\hello\WEB-INF\classes\Testj.class
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class Testj extends HttpServlet{
public void doGet(HttpServletRequest request,HttpServletResponse response)throws IOException,ServletException {
response.setContentType("text/html");
request.setAttribute("ename","baba");
RequestDispatcher view = request.getRequestDispatcher ("result.jsp");
view.forward(request,response);
}
}

result.jsp in D:\tomcat5.0\webapps\hello

<html>
<body>
<p>
name:${param.ename}
</body>
</html>

web.xml in D:\tomcat5.0\webapps\hello\WEB-INF
<?xml version="1.0" encoding="ISO-8859-1"?>

<!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>
<servlet>
<servlet-name>Testj</servlet-name>
<servlet-class>Testj</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Testj</servlet-name>
<url-pattern>/Testj</url-pattern>
</servlet-mapping>
</web-app>

http://localhost:8080/hello/Testj
gives
name:${param.ename}

plzzz someone help
 
Kathy Sierra
Cowgirl and Author
Rancher
Posts: 1589
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, I know this is probably not it, but I have to ask... have you verified that the version of Tomcat that's actually coming up is Tomcat 5 and not an earlier one?

What happens when you go to:

http://localhost:8080/ in your browser?

Otherwise, there's something I'm not seeing, but hopefully someone else will.

Hang in there,
Kathy
 
pallavi utukuri
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey kathy it is Tomcat 5.0.28
http://localhost:8080/
give me nice welcome page
that can be found in $CATALINA_HOME/webapps/ROOT/index.jsp

kathy plzz me.....am stuck with this for hours

 
Ramaswamy Srinivasan
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

This code doesn't work for me too. I am trying to spot the error. But the thing to be noted is request.getAttribute("ename")works fine and the result baba is displayed in the jsp.

Is there any special concern to use the name:${param.ename}in a JSP.

Could it be the effect of the <p> tag? but i tried to use it in a <td> too. No luck...

Any idea?

Cheers,
Swamy
 
Philippe Maquet
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Pallavi,

I've not the time right now to make a test, but what's I noticed is that your web.xml file references the wrong (old) 2.3 DTD, while it should reference the new schema (xsd) for version 2.4). An example of it is given on page 77 of Head First Servlet & JSP.

Regards,

Phil.

PS: BTW, your code excerpts would be easier to read if they where formatted with the UBB 'CODE' tag.
 
pallavi utukuri
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i tried xml from page 77 of HFS
<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/web-app_2_4.xsd"
version="2.4">

this gave me an error that hello/Testj cant be found!

then i tried

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

this worked but i got the output as:
name:

i.e EL is returning null value
then to check with html, i created
form.html in D:\tomcat5.0\webapps\hello
<html>
<body>
<form action ="result.jsp">
Name: <input type="text" name="ename">
<input type="submit">
</form>
now
http://localhost:8080/hello/form.html
is working absolutely fine
but y is calling from servlet Testj returning null
is my servlet code wrong
 
Bahadar Khan
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is how to resolve this issue.

Add isELIgnored="false" on top of your JSP page where you intend to use EL. I know this sounds crazy but that's how it works! I have Tomcat 5.0.28 etc.


cheers!
 
Colin Fletcher
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
EL should work by default...

Instead of telling each page that EL is not ignored, you can add this to your web.xml file:

<jsp-config>
<jsp-property-group>
<url-pattern>*.jsp</url-pattern>
<el-ignored>false</el-ignored>
</jsp-property-group>
</jsp-config>

If you do add a parameter in the servlet to the request object, the JSP page should be able to see it, without any qualifications... ${ename} should work.

param identifies parameters. the servlet defines an attribute, not a form parameter.



Hope this helps.
 
Bahadar Khan
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Collin,

isELIgnored=false is default behavior. So naturally one assumes that EL should work without adding any bells and whistles to any part of the web application it may be DD or individual JSP page. The problem in hand is some implementation issue with Tomcat 5.0.28. It doesn't process EL tags by defualt, which it should.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic