This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Java bean in servlet  RSS feed

 
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.
 
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.
 
Ranch Hand
Posts: 1512
  • 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
 
Ranch Hand
Posts: 124
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
exactly..
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!