Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EL s not running

 
Abhra Kar
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I hava to class in package foo.
package foo;
public class Person {
public String name;
public Dog dog;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Dog getDog(){
return dog;
}
public void setDog(Dog dog){
this.dog=dog;
}}
package foo;
public class Dog{
public String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}}
and a servlet
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class s1 extends HttpServlet {
public void doGet(HttpServletRequest req,HttpServletResponse res)
throws IOException,ServletException{

foo.Person p = new foo.Person();
p.setName("Evan");

foo.Dog dog=new foo.Dog();
dog.setName("Spike");
p.setDog(dog);
req.setAttribute("person",p);
RequestDispatcher view =req.getRequestDispatcher("result.jsp");
view.forward(req,res);
}}

now when I use this- Dog's name is : ${person.dog.name} in result.jsp then I get the output
Dog's name is : ${person.dog.name} instead of getting "spike"
but this is working fine --
<%= ((foo.Person) request.getAttriute("person")).getDog().getName() %>
Why ?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You probably did not set your web.xml properly. Check this FAQ, especially this section (servlets 2.4)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic