• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

accessing beans in servlet

 
geeta vemula
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • 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
 
Omer Haderi
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
now its working.. thanks,
 
Omer Haderi
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • 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!
 
Himanshu Kansal
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • 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
  • 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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic