Win a copy of Rust Web Development this week in the Other Languages 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

unable to access class from jsp...

 
Ranch Hand
Posts: 763
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ???
 
Rancher
Posts: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 763
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ???
 
Greenhorn
Posts: 15
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic