Packages and CLASSPATH

A

athul.venugopal

Hi,

My doubt is regarding packages and CLASSPATH.
I am using Tomcat4.1

My directory structure looks like this,
webapps\
appname\
WEB-INF\
build.xml
classes\
\in
\co
\packagename
RequestHandler.class
lib\
src\
\in
\co
\packagename
RequestHandler.java


My html form look like this:
<form action="in.co.packagename.RequestHandler" method="GET">
<input type="text" name="name"> <br>
<input type="submit" value="submit">
</form>

The first line of RequestHandler.java is :
package in.co.packagename;

Now when I submits the form, I gets an error like

The requested resource (/appname/in.co.packagename.RequestHandler) is
not available


I guess, it is due to some conflicts between packagename and CLASSPATH.
Can anyone please tell the sequence of events happening here.

-Regards,
Athul.
 
M

Mario Winterer

Hi!

I'm not sure what exactly you want to do, but it seems you try to write a html form that submits it data to a java class named
"in.co.packagename.RequestHandler".
Guessing that this is what you want, consider the following:

1) The java class "RequestHandler" must be a HTTPServlet - so it must extend the class javax.servlet.http.HttpServlet.

2) you cannot send a HTTP-request to a servlet by using the servlet's classname for the action attribut of your form tag.
You can just send the request to an URI that does exist (e.g. a concrete file in your webapp or a virtual path). So you have two
possibilities:

a) Map your servlet to a virtual path and use this path in the action attribute. The mapping can be done in web.xml which must be
inside WEB-INF directory
b) Use the generic mapping "servlet/in.co.packagename.RequestHandler". This is not recommended due to security reasons and this
feature is not enabled by default in Tomcat 4.1

In general, you should have a look at the application developer's guide for tomcat webserver:
http://jakarta.apache.org/tomcat/tomcat-4.1-doc/appdev/index.html

More documenation/tutorials etc. can be found at:
http://java.sun.com/products/servlet/docs.html


Best regards,
Tex
 
R

Raymond DeCampo

Hi,

My doubt is regarding packages and CLASSPATH.
I am using Tomcat4.1

My directory structure looks like this,
webapps\
appname\
WEB-INF\
build.xml
classes\
\in
\co
\packagename
RequestHandler.class
lib\
src\
\in
\co
\packagename
RequestHandler.java


My html form look like this:
<form action="in.co.packagename.RequestHandler" method="GET">
<input type="text" name="name"> <br>
<input type="submit" value="submit">
</form>

The first line of RequestHandler.java is :
package in.co.packagename;

Now when I submits the form, I gets an error like

The requested resource (/appname/in.co.packagename.RequestHandler) is
not available


I guess, it is due to some conflicts between packagename and CLASSPATH.
Can anyone please tell the sequence of events happening here.

This has nothing to do with packages or classpaths. You need to look up
how to configure a servlet container using the web.xml file.

Here is the sequence of events, as you have written the code:

1) The user submits the form
2) The browser constructs a GET request for the relative URL
"in.co.packagename.RequestHandler". Presumably the page was served from
the directory /appname, which makes the resulting URL something like
http://localhost:8080/appname/in.co.packagename.RequestHandler?name=Bob&submit=submit.
3) The server processes the request for the above URL. It looks for
something on your server that corresponds to
"/appname/in.co.packagename.RequestHandler".
a) First it consults the servlet mappings listed in the web.xml.
b) Not finding a servlet mapping, it tries to find the file
webapps\appname\in.co.packagename.RequestHandler
c) Not finding either of these it throws an exception
NOTE: There may be other steps here I am overlooking, but these are
the most relevant.

Usually what people do is create a logical URL for their servlet and
then map the URL to the servlet class in the web.xml.

HTH,
Ray
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top