The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Tomcat with servlet and servlets paths

Discussion in 'General Discussion' started by dgbaker, Nov 26, 2002.

  1. dgbaker

    dgbaker Well-Known Member
    PartnerNOC

    Joined:
    Sep 20, 2002
    Messages:
    2,578
    Likes Received:
    3
    Trophy Points:
    38
    Location:
    Toronto, Ontario Canada
    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
     
  2. moronhead

    moronhead Well-Known Member

    Joined:
    Aug 12, 2001
    Messages:
    706
    Likes Received:
    0
    Trophy Points:
    16
    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
     
  3. moronhead

    moronhead Well-Known Member

    Joined:
    Aug 12, 2001
    Messages:
    706
    Likes Received:
    0
    Trophy Points:
    16
    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
     
  4. dgbaker

    dgbaker Well-Known Member
    PartnerNOC

    Joined:
    Sep 20, 2002
    Messages:
    2,578
    Likes Received:
    3
    Trophy Points:
    38
    Location:
    Toronto, Ontario Canada
    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.
     
  5. jsteel

    jsteel Well-Known Member

    Joined:
    Jul 4, 2002
    Messages:
    646
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    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
     
  6. dgbaker

    dgbaker Well-Known Member
    PartnerNOC

    Joined:
    Sep 20, 2002
    Messages:
    2,578
    Likes Received:
    3
    Trophy Points:
    38
    Location:
    Toronto, Ontario Canada
    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.
     
  7. moronhead

    moronhead Well-Known Member

    Joined:
    Aug 12, 2001
    Messages:
    706
    Likes Received:
    0
    Trophy Points:
    16
    [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
     
  8. moronhead

    moronhead Well-Known Member

    Joined:
    Aug 12, 2001
    Messages:
    706
    Likes Received:
    0
    Trophy Points:
    16
    Duplicate!
     
  9. dgbaker

    dgbaker Well-Known Member
    PartnerNOC

    Joined:
    Sep 20, 2002
    Messages:
    2,578
    Likes Received:
    3
    Trophy Points:
    38
    Location:
    Toronto, Ontario Canada
    * 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.
     
  10. moronhead

    moronhead Well-Known Member

    Joined:
    Aug 12, 2001
    Messages:
    706
    Likes Received:
    0
    Trophy Points:
    16
    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
     
  11. dgbaker

    dgbaker Well-Known Member
    PartnerNOC

    Joined:
    Sep 20, 2002
    Messages:
    2,578
    Likes Received:
    3
    Trophy Points:
    38
    Location:
    Toronto, Ontario Canada
    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&
     
  12. kt

    kt Active Member

    Joined:
    May 4, 2002
    Messages:
    40
    Likes Received:
    0
    Trophy Points:
    6
    acutally you should thank Nick for this =o)
     
  13. moronhead

    moronhead Well-Known Member

    Joined:
    Aug 12, 2001
    Messages:
    706
    Likes Received:
    0
    Trophy Points:
    16
    [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?
     
  14. dgbaker

    dgbaker Well-Known Member
    PartnerNOC

    Joined:
    Sep 20, 2002
    Messages:
    2,578
    Likes Received:
    3
    Trophy Points:
    38
    Location:
    Toronto, Ontario Canada
    [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.
     
  15. casey

    casey Well-Known Member

    Joined:
    Jan 17, 2003
    Messages:
    2,303
    Likes Received:
    0
    Trophy Points:
    36
    Location:
    If there is trouble, it will find me
    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.

     
  16. RisingHost

    RisingHost Member

    Joined:
    Feb 9, 2003
    Messages:
    21
    Likes Received:
    0
    Trophy Points:
    1
    Casey I believe this is what it should look like:
     
  17. casey

    casey Well-Known Member

    Joined:
    Jan 17, 2003
    Messages:
    2,303
    Likes Received:
    0
    Trophy Points:
    36
    Location:
    If there is trouble, it will find me
    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.
     
    #17 casey, Apr 2, 2003
    Last edited: Apr 3, 2003
  18. RisingHost

    RisingHost Member

    Joined:
    Feb 9, 2003
    Messages:
    21
    Likes Received:
    0
    Trophy Points:
    1
    Here is the code I added to the server.xml file in order to enable port 8080
    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:
     
  19. casey

    casey Well-Known Member

    Joined:
    Jan 17, 2003
    Messages:
    2,303
    Likes Received:
    0
    Trophy Points:
    36
    Location:
    If there is trouble, it will find me
    Is there something I need to do to get port 8080 working?
     
  20. RisingHost

    RisingHost Member

    Joined:
    Feb 9, 2003
    Messages:
    21
    Likes Received:
    0
    Trophy Points:
    1
    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).
     
Loading...

Share This Page