• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

accessing beans in servlet

 
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all,

I have written a Bean called PersonBean in the path C:\Tomcat 4.1\webapps\ch1\WEB-INF\classes\PersonBean.java
and i am able to execute this (below is the code)




And i have written another servlet called PersonServlet in C:\Tomcat 4.1\webapps\ch1\WEB-INF\classes\PersonServlet.java
(it is the same directory structure as above

code is




But it is showing errors that PersonBean is unresolved symbol. what i can do so that PersonServlet can recognize PersonBean??

Thanks,
Geeta
 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try to compile by adding to the classpath the (.) dot operator

ex: javac -classpath .;classes;C:\programming\apache-tomcat-5.5.27\common\lib\servlet-api.jar -d classes Test.java
 
geeta vemula
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
no it is not working that way too.
is there any other way? is my code right?

thanks,
geeta
 
geeta vemula
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
now its working.. thanks,
 
Omer Haderi
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if your code compiles fine and you get the error at runtime then the problem must be in your jsp. When container tries to compile the jsp at runtime it does not find any import statement for the PersonBean. You should import the PersonBean in your jsp with the page directive.

The code looks fine (it should be better in package) ex:


do the following in your jsp: <%@ page import="com.example.model.PersonBean" %>

must work!
 
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would prefer using atleast 1 package than default.
 
Omer Haderi
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just for reference

As of JSP 2.0 it is illegal to refer to any class from the default package.

Therefore all classes that are referred by JSPs must be at least in one package!
 
I knew I would regret that burrito. But this tiny ad has never caused regrets:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic