• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Error testing EL with bean

 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Following is the jsp I am using to test EL.
Line Bean : ${requestScope.sniferdog.name} throws exception saying it can not find property name. If anybody finds an answer please let me know.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">;
<%@page import="java.util.*"
contentType="text/html" pageEncoding="UTF-8"%>
<%!
class SniferDog{
private String name="Snifer Dog";
private StringBuffer logs=new StringBuffer("No Logs");

String getName(){
return name;
}

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

StringBuffer getLogs(){
return logs;
}

void setLogs(StringBuffer _logs){
this.logs=_logs;
}
}
%>
<%
ArrayList list=new ArrayList();
list.add("1");
list.add("dog");
list.add("2");
Map map=new HashMap();
map.put("dog", "Snifer Dog");
map.put("string1", "1");
map.put("Integer1", Integer.valueOf(1));
request.setAttribute("list", list);
request.setAttribute("map", map);
request.setAttribute("sniferdog", new SniferDog());
request.setAttribute("abc", "asdf");
%>


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h2>Hello World!</h2>
RequestScope : ${requestScope.list["1"+"1"]}<br/>
Map : ${map["Integer1"]} <br/>
Bean : ${requestScope.sniferdog.name} <br/>
<%=((SniferDog)request.getAttribute("sniferdog")).getName()%>
Logical : ${true||false&&false}
</body>
</html>
 
Ranch Hand
Posts: 71
Hibernate Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

It seems to be a problem with the access modifiers . EL may not be able to access the property if those are not available through methods which are public. In that case if you make the methods public then the class also has to be changed accordingly. This would work if you change the access modifiers to public in the method level as well as class level.

public class SnifferDog{

public String getName(){}..
public void setName(String name){}...

}

hope that helps

Best Regards,
Ranil
 
Nimit Shah
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
These methods were public when I started coding. It did not work.

However it all works with <%=((SniferDog)request.getAttribute("sniferdog")).getName()%>
 
Nimit Shah
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
any help?
 
Ranil Liyana Arachchige
Ranch Hand
Posts: 71
Hibernate Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you make the Class public ?
 
What? What, what, what? What what tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic