Find the answer to your Linux question:
Results 1 to 1 of 1
Have been googling and reading many web sites but my HelloWorldS servlet never works. I am trying to keep it simple, for now, no JSP, no HTML, no WAR, no ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jul 2012
    Posts
    5

    Manual Deploy 1st servlet tomcat6 fail, try login t6 manager, admin


    Have been googling and reading many web sites but my HelloWorldS servlet never works.
    I am trying to keep it simple, for now, no JSP, no HTML, no WAR, no packages.
    In the browser, I am using the locallhost:8080, with various strings after that,
    but always get 404 error, from tomcat6-formatted page.

    I got frustrated with that, so read that manager and admin commands
    may be of some use to my problem; I forgot exactly how, but, that is another (re-) investigation.
    At first I got mini-windows with user/pw fields to fill in which kept coming back (try again).
    Later, changed the admin and manager xml so it reflected the example in the file and tried again.
    Now I get the 404 error here also.

    Details to follow in next post.

    Also, internal search function here, found nothing.

    ============= I tried a reply post did not work, I put detaild info here. ==================
    Ubuntu 10.04, tomcat6, open java, Firefox browser
    Trying to compile and unit test a java servlet on the same computer.

    Try compile a servlet: works.
    Intall of tomcat6 : works (I can get "welcome" html page.)
    (I also get various tomcat6 error messages to the browser-firefox.)

    Deploy servlet in tomcat6: does not work.
    Deploy (configure & login) manager & admin to see what's wrong: no workie.

    Put shell variable defs here. Take effect at shell startup.
    /etc/profile
    -----
    Here are shell variables.

    JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk
    CATALINA_HOME=/usr/share/tomcat6
    CATALINA_BASE=/var/lib/tomcat6
    -----
    Start and Stop tomcat6 on command line, for Ubuntu.
    (tomcat6 does seem to be answering without a cl startup)

    sudo /etc/init.d/tomcat6 start
    sudo /etc/init.d/tomcat6 stop

    -----
    To find the tomcat process & pid on a command line.
    ps -ef | grep tomcat
    ------
    To find info about a process.
    pmap <pid>

    ------
    Put manager and admin defs and passwords here.(done)

    $CATALINA_BASE/conf/tomcat-users.xml

    Content below.

    :/var/lib/tomcat6/conf$ sudo more tomcat-users.xml

    <?xml version='1.0' encoding='utf-8'?>
    <!--
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements. See the NOTICE file distributed with
    this work for additional information regarding copyright ownership.
    The ASF licenses this file to You under the Apache License, Version 2.0
    (the "License"); you may not use this file except in compliance with
    the License. You may obtain a copy of the License at

    apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
    -->
    <tomcat-users>
    <!--
    <role rolename="tomcat"/>
    <role rolename="role1"/>



    <user username="tomcat" password="tomcat" roles="tomcat"/>
    <user username="both" password="tomcat" roles="tomcat,role1"/>
    <user username="role1" password="tomcat" roles="role1"/>

    <role rolename="manager"/>
    <role rolename="admin"/>
    <user username="manager" password="secretpw" roles="manager"/>
    <user username="bothma" password="secretpw" roles="manager,admin"/>
    <user username="admin" password="secretpw" roles="admin"/>


    -->
    </tomcat-users>



    ------
    Put servlet defs here. (done)

    CATALINA_HOME=/usr/share/tomcat6
    ------
    The packagename approach, seems a further complication that I have not used.

    webapps/appName/WEB-INF/classes/packageName

    localhost/appName/servlet/packageName.ServletName

    nords.wordpress.com/2010/07/29/how-to-package-your-tomcat-webapp/

    From
    tomcat.apache.org/tomcat-6.0-doc/appdev/deployment
    a quote
    /WEB-INF/classes/ - This directory contains any Java class files (and associated resources) required for your application, including both servlet and non-servlet classes, that are not combined into JAR files. If your classes are organized into Java packages, you must reflect this in the directory hierarchy under /WEB-INF/classes/. For example, a Java class named com.mycompany.mypackage.MyServlet would need to be stored in a file named /WEB-INF/classes/com/mycompany/mypackage/MyServlet.class.
    ------
    From
    tomcat.apache.org/tomcat-6.0-doc/appdev/deployment


    a quote
    Web Application Deployment Descriptor
    ...
    "basic web.xml file"
    (a link to tomcat.apache.org/tomcat-6.0-doc/appdev/web.xml.txt )
    I do not yet understand what this means and where it fits.
    ...
    NOTE - The Servlet Specification includes a Document Type Descriptor (DTD) for the web application deployment descriptor, and Tomcat 6 enforces the rules defined here when processing your application's /WEB-INF/web.xml file. In particular, you must enter your descriptor elements (such as <filter>, <servlet>, and <servlet-mapping> in the order defined by the DTD (see Section 13.3).
    (no link provided) Where is Section 13.3? I must google this.
    ------
    tomcat.apache.org/tomcat-6.0-doc/default-servlet
    Reading this now. Not immediately usefull or understandable.
    ------
    Servlet definition, and so on.

    :~$ cd $CATALINA_HOME

    :/usr/share/tomcat6$ ll
    total 32
    drwxr-xr-x 6 root root 4096 2012-07-20 22:00 ./
    drwxr-xr-x 323 root root 12288 2012-07-20 21:58 ../
    drwxr-xr-x 2 root root 4096 2012-07-18 02:16 bin/
    drwxr-xr-x 2 root root 4096 2012-07-18 02:16 lib/
    drwxr-xr-x 4 root root 4096 2012-07-20 22:00 skel/
    drwxr-xr-x 4 curly root 4096 2012-07-23 00:44 webapps/
    :/usr/share/tomcat6$ cd webapps
    :/usr/share/tomcat6/webapps$ ll
    total 16
    drwxr-xr-x 4 curly root 4096 2012-07-23 00:44 ./
    drwxr-xr-x 6 root root 4096 2012-07-20 22:00 ../
    drwxr-xr-x 3 root root 4096 2012-07-18 02:16 default_root/
    drwxr-xr-x 3 curly root 4096 2012-07-23 00:12 dir-j1/
    :/usr/share/tomcat6/webapps$ cd dir-j1
    :/usr/share/tomcat6/webapps/dir-j1$ dir
    WEB-INF
    :/usr/share/tomcat6/webapps/dir-j1$ cd W*
    :/usr/share/tomcat6/webapps/dir-j1/WEB-INF$ ll
    total 16
    drwxr-xr-x 3 root root 4096 2012-07-23 00:37 ./
    drwxr-xr-x 3 curly root 4096 2012-07-23 00:12 ../
    drwxr-xr-x 2 root root 4096 2012-07-20 16:51 classes/
    -rw-r--r-- 1 root root 231 2012-07-23 00:37 web.xml
    :/usr/share/tomcat6/webapps/dir-j1/WEB-INF$ more web.xml
    <servlet>
    <servlet-name>sn-hws</servlet-name>
    <servlet-class>HelloWorldS</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>sn-hws</servlet-name>
    <url-pattern>/url-hws</url-pattern>
    </servlet-mapping>
    :/usr/share/tomcat6/webapps/dir-j1/WEB-INF$ dir classes
    HelloWorldS.class
    :/usr/share/tomcat6/webapps/dir-j1/WEB-INF$ ll classes
    total 12
    drwxr-xr-x 2 root root 4096 2012-07-20 16:51 ./
    drwxr-xr-x 3 root root 4096 2012-07-23 00:37 ../
    -rw-r--r-- 1 root root 820 2012-07-20 16:51 HelloWorldS.class
    :/usr/share/tomcat6/webapps/dir-j1/WEB-INF$

    ------
    At coreservlets.com/Apache-Tomcat-Tutorial/test-server
    they describe how to depoy a packageless servlet. Not so clear on paths.
    Where is does this path start?
    install_dir/webapps/ROOT/WEB-INF/classes
    Full Quote:

    Test 1: A Servlet That Does Not Use Packages

    The first servlet to try is a basic one: no packages or utility (helper) classes. Rather than writing your own test servlet, you can just download HelloServlet.java into your development directory, compile it, and copy the .class file to install_dir/webapps/ROOT/WEB-INF/classes. Right-click on the link to download the file to your system. Note: in all versions of Apache Tomcat, the location for servlets in the default Web application is install_dir/webapps/ROOT/WEB-INF/classes. However, in some versions of Tomcat (including Tomcat 6.0.10), the system doesn't create the classes directory for you automatically. No problem: just create it yourself. (Remember that case matters: WEB-INF is upper case, classes is lower case.) Note that my preconfigured Apache Tomcat version already contains the classes directory and already has the sample servlets.
    ------

    Had to edit the above because forum computer did not want me to post urls until I had 15 posts.
    Last edited by leaf_also; 07-26-2012 at 03:22 AM. Reason: reformat

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •