wood burning stoves 2.0*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Help me EL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Help me EL" Watch "Help me EL" New topic
Author

Help me EL

Ramnathan Ravindran
Ranch Hand

Joined: May 12, 2004
Posts: 46
Ranchers,
I have a query. I am currently trying out EL. I have a servlet which dispatches the request and response to a JSP. In the JSP, i have a line like this : ${person.name}. The servlet sets an attribute "person" into the request. Now when i run the application. I get ${person.name} printed and not the attribute. Kindly help me if you know what the problem is? Kathy i surely need yours. I hope you know what the problem might be?


Regards<br />- Ramnathan<br />SCJP 1.4, SCBCD 1.3, OCA
Vanessa Danin
Ranch Hand

Joined: Oct 04, 2004
Posts: 34
I gather that 'person' is a request-scoped bean that has a getName() method. To print it out with JSTL EL the syntax is:
<cut value="${requestScope.person.name}" />
I hope this helps you.

[ October 11, 2004: Message edited by: Vanessa Danin ]
[ October 11, 2004: Message edited by: Vanessa Danin ]
Ramnathan Ravindran
Ranch Hand

Joined: May 12, 2004
Posts: 46
Vanessa,
Thanks for the reply, but that didnt help. i still get
${requestScope.person.name} printed out in the html as a normal text. Any help?
Susanta Chatterjee
Ranch Hand

Joined: Aug 12, 2002
Posts: 102
Make sure, your servlet container supports Servlet 2.3 and JSP 1.2. And the web.xml in your web application must have doc type definition as:



Read this. I remember, when I started learning JSTL, I did not have this doctype and I had the same problem.
Ramnathan Ravindran
Ranch Hand

Joined: May 12, 2004
Posts: 46
Susanta,
I did check that. But the doctype in the web.xml is there. I am highly confused.

This is my servlet code :

public class BeanServlet extends HttpServlet {
public void doGet(HttpServletRequest request,HttpServletResponse response) throws IOException,ServletException
{
String str = request.getParameter("name");
TestBean tb = new TestBean();
tb.setName(str);
request.setAttribute("testbean",tb);
RequestDispatcher dispatcher = request.getRequestDispatcher("jsp/Bean.jsp");
dispatcher.forward(request,response);
}
}


This is the code in my Bean.jsp:
Name is : ${requestScope.testbean.name}

The result when i run the application
Name is : ${requestScope.testbean.name}

Any help guys.
Roger Yates
Ranch Hand

Joined: Aug 31, 2004
Posts: 118

Make sure, your servlet container supports Servlet 2.3 and JSP 1.2


For EL expressions and SCWCD 1.4 you will need a container that supports Servlet 2.4 and JSP 2.0.

e.g. Tomcat 5 (Tomcat 4 supports 2.3/1.2 and is ok for SCWCD 1.3, but...!).

EL was added to the JSP 2.0 spec, so I doubt a JSP1.2 supporting container would know what to do with it, unless you'd downloaded something extra...

Try Tomcat 5


Cheers,<br />Roger<br />SCJP 1.2, 1.4, SCBCD 1.3, SCWCD 1.4
Ramnathan Ravindran
Ranch Hand

Joined: May 12, 2004
Posts: 46
Roger i am using Tomcat 5.0.28.
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
I guess Vanessa's answer should be correct.

Nick


SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982

For EL expressions and SCWCD 1.4 you will need a container that supports Servlet 2.4 and JSP 2.0.

Dont mix up. EL does not come with JSP 2.0!

EL comes with JSTL, which if just we put jstl.jar in the lib, we can use EL in JSPs.

Nick
Vanessa Danin
Ranch Hand

Joined: Oct 04, 2004
Posts: 34
Ram, you say that the code in your JSP is this:
Name is : ${requestScope.testbean.name}
That is incorrect as it is not enclosed by a reference to a JSTL library.

As per my example above it should be enclosed in the core library's out tag and assigned to its value attribute in quotes like this:
Name is : <cut value="${requestScope.testbean.name}" />

Otherwise it will simply write out the expression syntax as a literal string in the HTML. Hope this solves your problem.
Roger Yates
Ranch Hand

Joined: Aug 31, 2004
Posts: 118
Nick,

Dont mix up. EL does not come with JSP 2.0!


I beg to differ.
JSP does come with a container that implements JSP2.0. To use JSTL you still need to add jstl.jar, but you can happily use EL in a JSP2.0-compliant container such as Tomcat 5.0.28 without having added jstl.jar.
I'm not saying that EL didn't exist before JSP2.0, but that it was incorporated into the spec with JSP2.0.
With JSP2.0 EL is there, in the container, as soon as you install.
For JSTL support, you still need to add jstl.jar, but not for EL.

The JSP2.0 spec, page xxii, says:
EL expressions will be ignored by default in JSP 1.2 applications. When upgrading a web application to JSP 2.0, EL expressions will be interpreted by default.

and on page 1-63:
The language was initially defined by the JSP StandardTag Library (JSTL) 1.0 specification, but is now incorporated in the JSP specification, and extended with new features.



Ram,

I've tried your code and it works fine on my setup.
Initially I didn't send a name parameter so nothing came out, but entering a name on one form and using your code to setup the bean and all was fine.
With respect to earlier comments about web.xml, here's what I have in mine: Can you update your web.xml with this instead, and then stop/start tomcat to see if makes any difference:
<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">


- I also tried deleting everything except <web-app> and it still worked!
The only way I can reproduce your problem is by turning off EL.

If the above doesn't help, did you turn it off in your DD somewhere? Try forcing EL on by adding this to your JSP page:
[ October 13, 2004: Message edited by: Roger Yates ]
Ramnathan Ravindran
Ranch Hand

Joined: May 12, 2004
Posts: 46
Roger,
Bingoooo.
Thats what i found out what the problem was. Thanks Ranchers for the help. I have atlast got what i want working.
Roger Yates
Ranch Hand

Joined: Aug 31, 2004
Posts: 118
Ram,

Hooray!

Was it web.xml or page directive that you needed?
Ramnathan Ravindran
Ranch Hand

Joined: May 12, 2004
Posts: 46
Roger,
I had to make the change in the web.xml
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help me EL
 
Similar Threads
EL problem !!!
Jsps and Servlets
Tomcat's difficulty in evaluating an EL expression
Possible error on HFS and errata
EL Help please