• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problems getting servlets to work on Tomcat 4

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am having problems getting servlets to work on my host server.
I am using apache/tomcat 3 as my development server and the host is using apache/tomcat 4.
They have setup tomcat to pick up servlets in the following folder
www.drumpellier.com/public_html/jserv
I have tried putting a simple HelloWorld servlet in
www.drumpellier.com/public_html/jserv/WEB-INF/classes/
folder which worked fine, but when I upload the my files to the server I cant get any servlets to work.
I am hitting a servlet called Controller from the following link.
www.drumpellier.com/jserv/servlet/com.golfclub.Controller?HsMethod=1

Which then produces the following error
************************************************
HTTP Status 404 - /jserv/servlet/com.golfclub.Controller
With the description as:
description The requested resource (/jserv/servlet/com.golfclub.Controller) is not available
************************************************
The servlet is in the following folder:
www.drumpellier.com/public_html/jserv/WEB-INF/classes/com/golfclub/Controller.class
and the web.xml is in the following folder
www.drumpellier.com/public_html/jserv/WEB-INF/web.xml
the web.xml referring to this servlet is as follows
************************************************
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>Controller</servlet-name>
<servlet-class>com.golfclub.Controller</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Controller</servlet-name>
<url-pattern>/com.golfclub.Controller</url-pattern>
</servlet-mapping>
</web-app>
**************************************************
I just want to make sure that everything I have done is correct.
I think the host may not be picking up the com, golfclub, folders, but I�m not sure.
Would it be better to create a war file and put it in the classes folder?
Any help greatly appreciated as Im totally stuck!
Craig
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the whole point of mapping servlets (or at least one of the points)... is to provide a public alias to your servlet class, so that you don't reveal to your user the package and class name; they don't really need to know this information.

It is likely that your host has disabled the /servlet/* mapping, so you will probably have to use the alias anyways.

I'd make the following change...
And call it like:

www.drumpellier.com/jserv/foo?HsMethod=1

'foo' can be replaced by anything you want.

as for this: Would it be better to create a war file and put it in the classes folder

WAR files don't go in the classes folder. They go either in a known location like the webapps folder under Tomcat's root (and since you're hosted, you probably don't have access to this folder)... or the location of a particular web-app's WAR file can be specified in server.xml (again you're hosted, so you probably don't have access to this file).
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm also going to move this to Apache/Tomcat forum...

While servlet mappings are generic, the /servlet/* mapping is Tomcat-specific, and after all, your title has "Tomcat" in it.
 
Craig Angus
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for replying, sorry I put this in the wrong place, I didn�t realise there was a Tomcat section!
I have a few more questions:
1)
I have written servlets in packages, to separate out the logic.
I have four servlets in the following folders
www.drumpellier.com/public_html/jserv/WEB-INF/classes/com/golfclub/MemberDetails
www.drumpellier.com/public_html/jserv/WEB-INF/classes/com/golfclub/CodeBehind_MemberDetails
www.drumpellier.com/public_html/jserv/WEB-INF/classes/com/golfclub/DataManager/MemberDetailsDM

www.drumpellier.com/public_html/jserv/WEB-INF/classes/com/golfclub/DBConnect/MemberDetailsDB

The web.xml is as follows


Only the CodeBehind_Memberdetails.class is called from the jsp files.
Do I need to change all of the <url-pattern> elements so that they all follow the web.xml below?

2)
Also using my previous web.xml, should I be able to call the servlet with
http://www.drumpellier.com/jserv/servlet/com.golfclub.Controller?HsMethod=1
without any problem?
It seems that anything under the folder
www.drumpellier.com/public_html/jserv/WEB-INF/classes/
works fine but if I put anything under the folder
www.drumpellier.com/public_html/jserv/WEB-INF/classes/com/golfclub/
I get the error 404 error with description The requested resource
(/jserv/servlet/com.golfclub.Controller) is not available.
Why does this happen?
3)
Its my understanding of the web.xml that

tells tomcat where to find the servlet.
Does this then mean that tomcat is not finding the servlet? And if so would the host need to include any folders under
www.drumpellier.com/public_html/jserv/WEB-INF/classes/
in the server.xml ias follows

this is a copy of the server.xml that the host is using.
4)
Are far as I know the way I have set the folders up everything should work. Is there anything the host may have missed out when setting up tomcat?
They previously had tomcat 3 working but I couldn�t get any files to work at all, they upgraded to tomcat 4 which allowed the jsps to work inside the jserv folder, but only basic servlets in the classes folder
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1) No, you don't *have* to. But you gain some advantages with the double-indirection (you call '/foo' from the browser, which calls the servlet named 'myXYZservlet', which finally resolves to 'com.mypackage.anotherpackage.className'). They include (but aren't limited to) hiding of class names, increased security, a "nice" looking address bar and the normal advantage of having an alias... being able to switch what something "points" to, without having to re-write anything that used the alias. All that, and it is the recommened way of doing things.

Having said that.. whatever way you choose to proceed, pick ONE and ALWAYS use that way. Either use the invoker servlet and call everything like /servlet/classNameHere or ALWAYS use an alias and never use /servlet.

2) depends.

*IF* your ISP has the invoker servlet enabled, then yes, you should be able to invoke your classes, with /servlet/classNameHere. In fact, if you go this route, you should probably leave your web.xml empty of servlet and servlet-mapping tags.

*IF* your ISP has disabled the invoker servlet, which they should, then serlvet/* should never work, unless you explicitly enable it, and you MUST provide servlet and servlet-mapping tags in appropriate pairings.

I think the answer to why the odd behaviour is happening is answered by your next question...

3) the servlet tag is 1/2 of how Tomcat finds servlets. YOU make a request of a certain url-pattern. So the servlet-mapping entries are the missing 1/2, and it's the 1st half as well. Your URL request is translated to a servlet-name, which is then translated to a servlet-class.

As for your ISP's file.. NO. I've never seen that before, and I think it's the cause of your trouble. A context's meaning is "web application". There is only one entry point to that application. Remove any entries with anything after /jserv (all the ones with /classes/etc/etc...)

4 ) See above. That server.xml file is *wrong*
[ March 26, 2003: Message edited by: Mike Curwen ]
 
Craig Angus
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I made the changes you suggested as follows.
I kept the web.xml as

and then called the servlet from the following url
http://www.drumpellier.com/jserv/com.golfclub.Controller?HsMethod=1
and its still not working!
But now instead of getting an Apache/tomcat error screen, Im getting the standard HTTP 404 - File not found screen.
Im thinking that it may be that the ISP haven't set up their Apache/tomcat combination properly and the when a servlet is requested Apache does not know where to find it.
Is this a correct assumption?
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe that this mapping problem will attack me soon as well. I have totally forgotten about all config files which has to be edited before everything runs smoothly.
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, that's very possible. I'd ask them what the proper way to call your servlets is.
 
Craig Angus
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, thanks for all the help so far!
I got the Host to check out things at there end and they have given me some feedback, as follows

Hi Craig,
I have had the response from next-level support. It seems that the
parameter HsMethod=1 is the one causing the 404
error.
If you intentionally misspell the parameter say hsmethod=1, you get a
tomcat error:
java.lang.NumberFormatException: null
at java.lang.Integer.parseInt(Integer.java:394)
at java.lang.Integer.parseInt(Integer.java:476)
at com.golfclub.Controller.doGet(Controller.java:45)
....
which means that apache does in fact forward the request to tomcat
appropriately.


I tried this and it does indeed give an error, as it should.
What I am thinking now is that the servlet can't find the jsp page that I try to redirect to from the servlet.
I am using the following code to redirect to the jsp

which I think is the older way to redirect servlets
Does this then mean that it is directory naming issue?
If the jsp page is in the directory
www.drumpellier.com/public_html/jserv/
and the servlet which is redirecting to the page which uses the above code, is in the following directory
www.drumpellier.com/public_html/jserv/WEB-INF/classes/com/golfclub/
then the servlet is looking for the jsp page in the directory above the servlet directory which is
www.drumpellier.com/public_html/jserv/WEB-INF/classes/com/
which is the wrong directory.
This would then cause a http 404 error as the file does not exist there.
if i was to use

would this redirect the servlet back up to the top level?
[i}www.drumpellier.com/public_html/jserv/[i]
Seems it is my sloppy coding problem!
 
Craig Angus
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Is it maybe worth mapping my jsps in the web.xml?
if so, what would the mapping be?
reply
    Bookmark Topic Watch Topic
  • New Topic