• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

servlet packages

 
dhana rangu
Ranch Hand
Posts: 65
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 149
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 65
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 149
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 65
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 149
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 65
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 149
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 65
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi


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

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

dhana
 
yamini nadella
Ranch Hand
Posts: 257
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try by keeping in ROOT application folder.
 
dhana rangu
Ranch Hand
Posts: 65
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yamini

can u put it in more detail..

thanks a lot
dhana
 
Arvind Chavar
Ranch Hand
Posts: 53
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 53
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic