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

Java bean in servlet

 
Ashu Jain
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I created a servlet that sets attribute in request scope as an instance of java bean class. My bean is named Person created directly under WEB-INF/classes folder. I have not used package foo as done in HFSJ.

After setting attribute, I have forwarded to a jsp page via requestdispatcher.

This is not working in jsp page -

<p> Hello::: </p>
<% Person p=(Person)request.getAttribute("Person"); %>
<%= p.getName()%>
<br><br>

It says :: Compiling 1 source file
[javac] C:\apache-tomcat-4.1.37\apache-tomcat-4.1.37\work\Standalone\localhost\testJSP\Tester_jsp.java:42: cannot resolve symbol
[javac] symbol : class Person
[javac] location: class org.apache.jsp.Tester_jsp
[javac] Person p=(Person)request.getAttribute("Person");

Please guide. Is it important to use package for bean class. If yes then why so.
 
Mi Ku
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you need to place your class into a package. It will not be recognized by the container if it is in the dafault package.
 
Ashu Jain
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes..u are right. It worked when i placed java bean in a package. Why this does not work default package.
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Probably because what the default package is called is dependent on the caontainer. So, no way to know what it actually is.

Originally posted by Ashu Jain:
yes..u are right. It worked when i placed java bean in a package. Why this does not work default package.
 
Ashu Jain
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
 
Surajsingh Thakur
Ranch Hand
Posts: 124
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
exactly..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic