Tomcat with servlet and servlets paths

dgbaker

Well-Known Member
PartnerNOC
Sep 20, 2002
2,531
10
343
Toronto, Ontario Canada
cPanel Access Level
DataCenter Provider
I've got it, the following needs to be added to web.xml in order for both servlet and servlets to be valid paths. This basically loads two invoker classes with different docroots.

Add this right after the current invoker

&servlet&
&servlet-name&invoker2&/servlet-name&
&servlet-class&org.apache.catalina.servlets.InvokerServlet&/servlet-class&
&init-param&
&param-name&debug&/param-name&
&param-value&0&/param-value&
&/init-param&
&load-on-startup&2&/load-on-startup&
&/servlet&

Add this right after the current invoker mapping

&servlet-mapping&
&servlet-name&invoker2&/servlet-name&
&url-pattern&/servlet/*&/url-pattern&
&/servlet-mapping&


Once this is done anything in WEB-INF/classes will work with servlet or servlets in url.
For example see:
http://server11.virtual-hosting.ca/servlet/IsItWorking
and
http://server11.virtual-hosting.ca/servlets/IsItWorking

Please note that this is with Tomcat 4.0.3
 

moronhead

Well-Known Member
Aug 12, 2001
706
0
316
David,

Could you give exact location of where to put those two additions, like a line in web.xml?

Also, where did you pick up the IsItWorking.class file from? I've got ApacheJServ 1.1.2 running on a server and just installed Tomcat 4.03. I just want to see if they'll work together or not.

Regards,
Norman
 

moronhead

Well-Known Member
Aug 12, 2001
706
0
316
OK, I've found it. Both &servlet& and &servlets& are now good to go.

I am getting a 404 when running a .class, e.g. HelloWWW:

Apache Tomcat/4.0.3 - HTTP Status 404 - /servlet/HelloWWW

--------------------------------------------------------------------------------

type Status report

message /servlet/HelloWWW

description The requested resource (/servlet/HelloWWW) is not available.

I have gone through all the usual steps and IsItWorking.class is returning the same ... It's Working message you are getting.

Any ideas what may be causing this?

Regards,

Norman
 

dgbaker

Well-Known Member
PartnerNOC
Sep 20, 2002
2,531
10
343
Toronto, Ontario Canada
cPanel Access Level
DataCenter Provider
Okay, so you've tomcat installed,

You put your class files in /home/user/www/WEB-INF/classes

Assured there is no direcrory in /home/user/www called servlet or servlets

Restarted Tomcat after putting class files in correct directory.

This one of the headaches, reloadable does not work. If a file is added to the classes directory, tomcat must restarted.

You checked to see that the owner of the files and directory for WEB-INF were correct.

You've tried both /servlet & /servlets in the URL.

Also another trick to to see if tomcat itself is working is to add to the server.xml file at around line 50 or so.

&!-- Define a non-SSL HTTP/1.1 Connector on port 8080 --&
&Connector className=&org.apache.catalina.connector.http.HttpConnector&
port=&8080& minProcessors=&5& maxProcessors=&75&
enableLookups=&true& redirectPort=&8443&
acceptCount=&10& debug=&0& connectionTimeout=&60000&/&

Restart tomcat, then goto port 8080 in your browser this should be tomcat's index page with some test scripts there.
 

jsteel

Well-Known Member
Jul 4, 2002
646
0
166
Atlanta, GA
Reloadable works just fine. I've got 8 servers with Tomcat 4.0.3 installed. You don't even need to use individual web.xml files for most things. The only time Tomcat really needs to be restart is:

1) To add another user (to read changes to server.xml)
or
2) To force a re-read of an individual web.xml file that a user has changed should they need it.

Keep in mind that restarting Tomcat IMPACTS all users on that server using it. If they are in the middle of transactions, you will lose their data. I'd recommend only restarting Tomcat as a nighlty cron job. The whole auto-restarting of Tomcat when you click the 'Install Servlets' link in WHM has fiorced me to just manually edit the httpd.conf and server.xml file for those users that need Tomcat.

I really wish there was a tweak setting to not perform the auto Tomcat restarts!

Jaz
 

dgbaker

Well-Known Member
PartnerNOC
Sep 20, 2002
2,531
10
343
Toronto, Ontario Canada
cPanel Access Level
DataCenter Provider
jsteel -

Thanks for the clarification. I had thought it needed to be done for classes directory changes as well. I know on one of our servers that has happened before (needing the restart everytime). I'll have to retest this now.
 

moronhead

Well-Known Member
Aug 12, 2001
706
0
316
[quote:da0cbe69a9][i:da0cbe69a9]Originally posted by dgbaker[/i:da0cbe69a9]

Okay, so you've tomcat installed,

You put your class files in /home/user/www/WEB-INF/classes

Assured there is no directory in /home/user/www called servlet or servlets

Restarted Tomcat after putting class files in correct directory.

This one of the headaches, reloadable does not work. If a file is added to the classes directory, tomcat must restarted.

You checked to see that the owner of the files and directory for WEB-INF were correct.

You've tried both /servlet & /servlets in the URL.

Also another trick to to see if tomcat itself is working is to add to the server.xml file at around line 50 or so.

&!-- Define a non-SSL HTTP/1.1 Connector on port 8080 --&
&Connector className=&org.apache.catalina.connector.http.HttpConnector&
port=&8080& minProcessors=&5& maxProcessors=&75&
enableLookups=&true& redirectPort=&8443&
acceptCount=&10& debug=&0& connectionTimeout=&60000&/&

Restart tomcat, then goto port 8080 in your browser this should be tomcat's index page with some test scripts there.
[/quote:da0cbe69a9]
Thanks. I actually realized I was using /servlets/ instead of /servlet/ and that was giving me a 404 before I mapped them both, thanks to your mod. There was one small edit that I needed to make in your mod and that was the &s&:

&url-pattern&/servlet[b:da0cbe69a9]s[/b:da0cbe69a9]/*&/url-pattern&

I downloaded the mailform servlet from coolservlets.com and it worked perfectly.

For &!-- Define a non-SSL HTTP/1.1 Connector on port XXXX --& I'd probably choose another port than 8080 as I believe that one is quite popular with hackers. ;)

I'm also trying to find out about:

* What's the connection string for MySQL

* What if the client wants to have access to their application's log files

Regards,

Norman
 

dgbaker

Well-Known Member
PartnerNOC
Sep 20, 2002
2,531
10
343
Toronto, Ontario Canada
cPanel Access Level
DataCenter Provider
* What's the connection string for MySQL
You need mysql-connector-java-2.0.14-bin.jar in the /usr/local/jakarta/jakarta-tomcat-4.0/lib directory

&%@ page import=&java.sql.*& %&
Connection connection = null;
Class.forName(&org.gjt.mm.mysql.Driver&).newInstance();
connection = DriverManager.getConnection(
&jdbc:mysql://localhost/DBNAME?user=DBUSER&password=&PASSWORD HERE&&);


* What if the client wants to have access to their application's log files

Logs are visible by anyone, but they are not separated by domain
/usr/local/jakarta/jakarta-tomcat-4.0/build/logs

You might be able to create a script that run daily and parses things out to different logs.
 

moronhead

Well-Known Member
Aug 12, 2001
706
0
316
Excellent, thanks David.

If someone wants to create an individual web.xml do you know if that has to go in WEB-INF?

Regards,

Norman
 

dgbaker

Well-Known Member
PartnerNOC
Sep 20, 2002
2,531
10
343
Toronto, Ontario Canada
cPanel Access Level
DataCenter Provider
Yes!

This is what a default one should look like

&?xml version=&1.0& encoding=&ISO-8859-1&?&

&!DOCTYPE web-app
PUBLIC &-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN&
&http://java.sun.com/j2ee/dtds/web-app_2.2.dtd&&

&web-app&
&welcome-file-list&
&welcome-file&
overview.html
&/welcome-file&
&/welcome-file-list&

&/web-app&
 

moronhead

Well-Known Member
Aug 12, 2001
706
0
316
[quote:232c90ead8][i:232c90ead8]Originally posted by kt[/i:232c90ead8]

actually you should thank Brad for this =o)[/quote:232c90ead8]What are you talking about, kt?
 

dgbaker

Well-Known Member
PartnerNOC
Sep 20, 2002
2,531
10
343
Toronto, Ontario Canada
cPanel Access Level
DataCenter Provider
[quote:7da6b7008a][i:7da6b7008a]Originally posted by kt[/i:7da6b7008a]

acutally you should thank Brad for this =o)[/quote:7da6b7008a]

Yes, What are you talking about? Please explain your comment.
 

casey

Well-Known Member
Jan 17, 2003
2,288
0
191
Could you post this one again, David? The forum switch seems to have garbled some code, and since I'm a newbie, I have no idea what's right.

Originally posted by dgbaker
I've got it, the following needs to be added to web.xml in order for both servlet and servlets to be valid paths. This basically loads two invoker classes with different docroots.

Add this right after the current invoker

&servlet&
&servlet-name&invoker2&/servlet-name&
&servlet-class&org.apache.catalina.servlets.InvokerServlet&/servlet-class&
&init-param&
&param-name&debug&/param-name&
&param-value&0&/param-value&
&/init-param&
&load-on-startup&2&/load-on-startup&
&/servlet&

Add this right after the current invoker mapping

&servlet-mapping&
&servlet-name&invoker2&/servlet-name&
&url-pattern&/servlet/*&/url-pattern&
&/servlet-mapping&


Once this is done anything in WEB-INF/classes will work with servlet or servlets in url.
For example see:
http://server11.virtual-hosting.ca/servlet/IsItWorking
and
http://server11.virtual-hosting.ca/servlets/IsItWorking

Please note that this is with Tomcat 4.0.3
 

RisingHost

Member
Feb 9, 2003
21
0
151
Casey I believe this is what it should look like:
Add this right after the current invoker

<servlet>
<servlet-name>invoker2</servlet-name>
<servlet-class>org.apache.catalina.servlets.InvokerServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>

Add this right after the current invoker mapping

<servlet-mapping>
<servlet-name>invoker</servlet-name>
<url-pattern>/servlets/*</url-pattern>
</servlet-mapping>
 

casey

Well-Known Member
Jan 17, 2003
2,288
0
191
Thanks RisingHost, that was it. Once I found my web.xml that was what was already in there, but without the correct code, I would never have found it. It's all gibberish to me.

On a second note, I cannot get the test page working on port 8080, but the code is in my server.xml file. I get a page not found error.
 
Last edited:

RisingHost

Member
Feb 9, 2003
21
0
151
Here is the code I added to the server.xml file in order to enable port 8080
<Connector className="org.apache.catalina.connector.http.HttpConnector"
port="8080" minProcessors="5" maxProcessors="75"
enableLookups="true" redirectPort="8443"
acceptCount="10" debug="0" connectionTimeout="60000"/>
much thanks to dgbaker for his documentation of this btw.

Once I got port 8080 working I was able to verify that servlets and JSP work using the examples.. but now that I've turned off port 8080 I haven't been able to verify servlet/ or servlets/ work with accounts that I have installed servlets on ; .war files expand but the servlets within dont seem to function. JSP works at least.
I'm stumped :confused:
 

casey

Well-Known Member
Jan 17, 2003
2,288
0
191
Is there something I need to do to get port 8080 working?
 

RisingHost

Member
Feb 9, 2003
21
0
151
Casey,
In order to get port 8080 working I had to add the "connector..." code mentioned in my last post and then restart tomcat. Aside from that it should work (i think).