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 Expressions

 
Nikhil Jain
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello there,

I was trying EL exp on tom cat.. The following is the example that I tried

<html>
<body>
<%= ((com.example.model.Person) request.getAttribute("person")).getName() %>
${person.name}
${person["name"]}
</body>
</html>

-----
Servlet:
package com.example.web;
import com.example.model.Person;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class First extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
com.example.model.Person p = new com.example.model.Person();
p.setName("Evan");
request.setAttribute("person", p);
RequestDispatcher view = request.getRequestDispatcher("result.jsp");
view.forward(request, response);
}

}

----
Model
package com.example.model;

public class Person {

private String name;

public void setName(String name) {
this.name = name;
}

public String getName() {
return this.name;
}

}

But I get the output as
Evan ${person.name} ${person["name"]}
There EL exp is not getting evaluated..

Can you please... help.. me on this...
 
Nikhil Jain
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I added the following lines in JSP
<%@ page isELIgnored="false" %> & now its working..But whats bothering me now is that...HFS says that by default the container will evaluate EL Expressions... But I had to add the above line specifically in my JSP... I have not mentioned anything about EL in the web.xml...

please confirm
 
Nikhil Jain
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys, I read other threads for this topic. That suggested me to use the latest 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">

So I added the above lines...but its still not working. I am using
I am using TOMCAT 5.5.15 with JDK1.5

Please help
 
Sunder Ganapathy
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It works perfectly. No need to set isElIgnored flag since by default,
the container evaluates EL expressions.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic