This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes servlet packages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "servlet packages" Watch "servlet packages" New topic
Author

servlet packages

dhana rangu
Ranch Hand

Joined: Oct 01, 2003
Posts: 65
Hi

i have created a servlet by name first.java in c:/dhana/first.java.
The code is

package testpack;
public class first extends Httpservlet
{
........

}

Now I donot understand how to procedd further.

I compiled the file and placed the class file
in c:/tomcat/webapps/examples/web-inf/classes/first.class


And now i am invoking the servlet using a html file as follows

<html>
<form action="http://localhost:8080/examples/servlet/testpack.first>
........
</html>

WHat i doubt is

1) how should we place the class file in tomcat.

2)Should we create a subdirectory with same name as the package name in tomcat/webapps/examples/web-inf/classes.

3)how should we indicate the path of the servlet in html file .Should we invoke with the fully qualified name...

with the above structure i am GEtting HTTP 404 error file not found.....

please help me with this

dhana
[ June 30, 2004: Message edited by: dhana rangu ]
arnel nicolas
Ranch Hand

Joined: Dec 16, 2003
Posts: 149
i think it should be in the "classes" directory under your WEB-INF.Other than that check your servlet-mapping in your web.xml configuration.

arnel
dhana rangu
Ranch Hand

Joined: Oct 01, 2003
Posts: 65
Hi

i actually placed the class file in
tomcat/webapps/examples/web-inf/classes
earlier it was a typo error...

Can u plz help me how i should change the mapping in web.xml

<servlet-mapping>
<servlet-name>first.java</servlet-name>
<url-pattern>/servlet/first.java</url-pattern>
<servlet-mapping>

<servlet>
<servlet-name>first</servlet-name>
<servlet-class>testpack.first</servlet-class>
</servlet>


this is the mapping i did...But i doubt if url-pattern is wrong..

plz help

[ July 01, 2004: Message edited by: dhana rangu ]

[ July 01, 2004: Message edited by: dhana rangu ]
[ July 01, 2004: Message edited by: dhana rangu ]
arnel nicolas
Ranch Hand

Joined: Dec 16, 2003
Posts: 149
Yes i guess you have a problem with the url-mapping as well as your servlet-class. Try doing this

<servlet-mapping>
<servlet-name>PrimeNumbers</servlet-name>
<url-pattern>/servlet/primeNumbers</url-pattern>
<servlet-mapping>

<servlet>
<servlet-name>PrimeNumbers</servlet-name>
<servlet-class>testpack.first</servlet-class>
</servlet>

Now in you in your HTML page you need to write this in your action, somewhat like this:

<html>
<form action="http://localhost:8080/examples/servlet/primeNumbers>
........
</html>

TAKE NOTE:You need to restart your servlet container to take effect.

I hope this helps.

arnel
[ June 30, 2004: Message edited by: arnel nicolas ]
dhana rangu
Ranch Hand

Joined: Oct 01, 2003
Posts: 65
hi

even in my second post I posted wrong mapping..I was in a hurry to get a suggestion .Thats why gone wrong

sorry for the confusion..The exact mapping I did was in my earlier post.I edited it.Even now i am getting the same error

HTTP Status 404 - /examples/servlet/first
--------------------------------------------------------------------------------

type Status report

message /examples/servlet/first
description The requested resource (/examples/servlet/first) is not available
arnel nicolas
Ranch Hand

Joined: Dec 16, 2003
Posts: 149
You are saying that the problem does not lie there. But basing from the error message, it seems that the servlet container cannot locate your class file. In my conclusion, there is problem on how you deploy your class file (i am referring to your first.class).

In your "classes" directory under WEB-INF, there should be another subdirectory called "testpack" directory and underneath is the first.class file. Thats how your web apps directory should look like.

Restart your server and try this again. Hope this helps. :roll:

arnel

[ July 01, 2004: Message edited by: arnel nicolas ]
[ July 01, 2004: Message edited by: arnel nicolas ]
dhana rangu
Ranch Hand

Joined: Oct 01, 2003
Posts: 65
hi arnel

I created a subdirectory in web-inf/classes/testpack and place first.class file there .

restarted tomcat..but still the same error




[ July 01, 2004: Message edited by: dhana rangu ]
arnel nicolas
Ranch Hand

Joined: Dec 16, 2003
Posts: 149
Ok then going back from your previous posting you have the following inyour web.xml

<servlet-mapping>
<servlet-name>first.java</servlet-name>---> change this to <servlet-name>first</servlet-name>
<url-pattern>/servlet/first.java</url-pattern>---> change this to
<url-pattern>/servlet/first</url-pattern>
<servlet-mapping>

<servlet>
<servlet-name>first</servlet-name>
/*Should be the same with the above servlet name mapping*/
<servlet-class>testpack.first</servlet-class>
</servlet>

in your html try this:

<html>
<form action="http://localhost:8080/examples/servlet/first>
........
</html>

Restart your server then try again.

arnel
[ July 01, 2004: Message edited by: arnel nicolas ]
dhana rangu
Ranch Hand

Joined: Oct 01, 2003
Posts: 65
hi


Thanks for ur kind and detailed reply.............

NO LUCk even now.........

dhana
yamini nadella
Ranch Hand

Joined: Apr 13, 2004
Posts: 257
try by keeping in ROOT application folder.
dhana rangu
Ranch Hand

Joined: Oct 01, 2003
Posts: 65
yamini

can u put it in more detail..

thanks a lot
dhana
Arvind Chavar
Ranch Hand

Joined: May 16, 2001
Posts: 53
1) how should we place the class file in tomcat.
2)Should we create a subdirectory with same name as the package name in tomcat/webapps/examples/web-inf/classes.
Yes, the directory structure under classes folder should match your package name.In your case you will have to create a folder called testpack,and place the first.class in this folder.

3)how should we indicate the path of the servlet in html file .Should we invoke with the fully qualified name...

You need to configure the servlet in web.xml file and provide a servlet mapping,and then you could call the servlet from HTML pages using servlet mapping

<servlet>
<servlet-name>testpackSvlt<servlet-name>
<servlet-class>testpack.first<servlet-class>
<servlet>

<servlet-mapping>
<servlet-name>testpackSvlt<servlet-name>
<url-pattern>/servlet/testpackSvlt</url-pattern>
<servlet-mapping>

then you could call servlet from HTML as

<html>
<form action="/servlet/testpackSvlt">
........
</html>

The configurations element that I have provided may not be correct as I just typed whatever I remebered,at least it shows how you could do it.If you have problems refer to servlet dtd.

- Arvind
Arvind Chavar
Ranch Hand

Joined: May 16, 2001
Posts: 53
1) how should we place the class file in tomcat.
2)Should we create a subdirectory with same name as the package name in tomcat/webapps/examples/web-inf/classes.
Yes, the directory structure under classes folder should match your package name.In your case you will have to create a folder called testpack,and place the first.class in this folder.

3)how should we indicate the path of the servlet in html file .Should we invoke with the fully qualified name...

You need to configure the servlet in web.xml file and provide a servlet mapping,and then you could call the servlet from HTML pages using servlet mapping

<servlet>
<servlet-name>testpackSvlt<servlet-name>
<servlet-class>testpack.first<servlet-class>
<servlet>

<servlet-mapping>
<servlet-name>testpackSvlt<servlet-name>
<url-pattern>/servlet/testpackSvlt</url-pattern>
<servlet-mapping>

then you could call servlet from HTML as

<html>
<form action="/servlet/testpackSvlt">
........
</html>

The configurations element that I have provided may not be correct as I just typed whatever I remebered,at least it shows how you could do it.If you have problems refer to servlet dtd.

- Arvind
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: servlet packages
 
Similar Threads
Servlet delivery in Tomcat
Need help urgently: problems compiling servlets
Tomcat 404 error
Having trouble getting Tomcat up and running
new errors!