Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General 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:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Java bean in servlet

 
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..
 
Mo-om! You're embarassing me! Can you just read a tiny ad like a normal person?
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic