• Post Reply Bookmark Topic Watch Topic
  • New Topic

unable to access class from jsp...

 
Jigar Naik
Ranch Hand
Posts: 762
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi in my web application.

i have one Project folder named Project one which contains

test.jsp and test1.class

and i wanna access a method from test1.class how do i do it.

i'm not using any IDE.

do i have to say somewhere Where are my classes ???

or do i have to put my classes Project/WEB-INF/classes directory ???

where will the container look for classes by default ???
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
WEB-INF/classes is the right place - that's where the container will find it. The JSP needs an import statement, but I'm sure you're aware of that. Oh, and make sure the class is part of a package if it doesn't have one yet.
 
Jigar Naik
Ranch Hand
Posts: 762
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
do i neeed web.xml ??? i guess no..as long as i know its for servlet class mapping...

so now my directory structure will be
Project/*.jsp
Project/WEB-INF/classes/Test.class

and the import statement in my jsp will look like



right ???
 
Karthick Sundaram
Greenhorn
Posts: 15
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jigar,

you need the web.xml by default..because that helps the container in identifying that it is a web-app.

Only thing for a JSP is that you don't have to have the <servlet> and the <servlet-mapping> tags in the web.xml
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do yourself a favor and put the class in a package - not all containers support beans that are in the default package (e.g. Tomcat 5 and later does not).

Apart from that it looks OK.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jigar Naik:
do i neeed web.xml ??? i guess no..as long as i know its for servlet class mapping...
...


See:
http://faq.javaranch.com/view?InvokerServlet
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ulf Dittmer:
not all containers support beans that are in the default package (e.g. Tomcat 5 and later does not).


<picking nits>
It's not actually the container, but the JVM that will refuse to import non packaged classes.
See:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4361575

This issue is showing up in containers, like Tomcat, that are on the forefront servlet spec (and thus JVM spec) development.
</picking nits>

The reason I brought this up is that it's important to understand that this issue will eventually affect everyone, regardless of what container you're using.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!