Results 1 to 8 of 8
  1. #1
    Join Date
    Nov 2013
    Posts
    4
    Rep Power
    0

    Default A very simple Servlets question

    Hey there good people, this is a very nooby question from someone who's just started out experimenting with the J2EE platform (using a virtual Tomcat container)

    I keep getting 404 not found errors with my simple servlet program - I've read up various guides, forum posts and Stack for the last couple of days but still to no avail. Almost pulling my hair out!

    [Java] Hello World J2EE - Pastebin.com

    [XML] web.xml - Pastebin.com

    Directory structure:

    helloworld(Root)
    |
    WEB-INF --- web.xml
    |
    classes
    |
    test --- HelloWorld.class


    I would greatly appreciate any help.

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,776
    Rep Power
    5

    Default Re: A very simple Servlets question

    Post the code here and not on some external site that is likely blocked by corporate firewall; post only the relevant code, not the entire project. Use code tags to format it correctly.

    Guide For New Members
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    Join Date
    Nov 2013
    Posts
    4
    Rep Power
    0

    Default Re: A very simple Servlets question

    Quote Originally Posted by gimbal2 View Post
    Post the code here and not on some external site that is likely blocked by corporate firewall; post only the relevant code, not the entire project. Use code tags to format it correctly.

    Guide For New Members

    Thanks for the response! and sorry for the bad forum etiquette.

    HelloWorld.class
    Java Code:
    	
    
        package test;
         
         
        import javax.servlet.*;
        import javax.servlet.http.*;
        import java.io.*;
         
         
        public class HelloWorld extends HttpServlet {
         
         
                                public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException
                                {
                                                PrintWriter out = response.getWriter();
                                                java.util.Date todaysDate = new java.util.Date();
                                                out.println("<html> " +
                                                                        "<body>" +
                                                                        "<h2>"  +
                                                                        todaysDate +
                                                                        "</h2>" +
                                                                        "<p>" +
                                                                        "Hello World" +
                                                                        "</p>" +
                                                                        "</body>" +
                                                                        "</html>"
                                                                        );
               
                                }
         
         
         
         
        }

    web.xml

    Java Code:
        <?xml version=”1.0” encoding=”ISO-8851-1” ?>
        <web-app xmlns=”http://java.sun.com/xml/ns/j2ee”
        xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
        xsi:schemaLocation=”http://java.sun.com/xml/ns/j2ee
        http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd”
        version=”2.4”>
        <servlet>
        <servlet-name>HWServlet</servlet-name>
        <servlet-class>test.HelloWorld</servlet-class>
        </servlet>
        <servlet-mapping>
        <servlet-name>HWServlet</servlet-name>
        <url-pattern>/hello</url-pattern>
        </servlet-mapping>
        </web-app>
    Directory structure
    Java Code:
    helloworld(Root)
    |
    WEB-INF --- web.xml
    |
    classes
    |
    test --- HelloWorld.class

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,776
    Rep Power
    5

    Default Re: A very simple Servlets question

    Looking good, although you may want to use minimally servlet spec 2.5; you are likely copy/pasting this from a very old source of information.

    So how are you attempting to access the servlet? Which url are you using?


    PS: it has nothing to do with etiquette, it is in your own best interest to post the minimal needed code here because it will give you a far better chance of getting an answer.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  5. #5
    Join Date
    Nov 2013
    Posts
    4
    Rep Power
    0

    Default Re: A very simple Servlets question

    Quote Originally Posted by gimbal2 View Post
    Looking good, although you may want to use minimally servlet spec 2.5; you are likely copy/pasting this from a very old source of information.

    So how are you attempting to access the servlet? Which url are you using?


    PS: it has nothing to do with etiquette, it is in your own best interest to post the minimal needed code here because it will give you a far better chance of getting an answer.

    I'm typing into my browser:

    http://localhost:8080/helloworld/hello



    *edit, I've gone into Tomcat Web Application Manager and apparently the helloworld application is not running for some reason - I think I may have stumbled across why it's inaccessible, but unsure on where to go from here.

  6. #6
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,776
    Rep Power
    5

    Default Re: A very simple Servlets question

    Well check your tomcat logs, there must be some error in there that is causing the webapp to not start.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,863
    Rep Power
    19

    Default Re: A very simple Servlets question

    You have deployed it to Tomcat's webapp directory?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  8. #8
    Join Date
    Nov 2013
    Posts
    4
    Rep Power
    0

    Default Re: A very simple Servlets question

    Quote Originally Posted by gimbal2 View Post
    Well check your tomcat logs, there must be some error in there that is causing the webapp to not start.

    This is the latest log entry, I'm not 100% sure but I think the error is something to do with my web.xml file ?

    Java Code:
    18-Nov-2013 16:34:57.112 INFO [main] org.apache.catalina.core.AprLifecycleListener.init The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files (x86)\Apache Software Foundation\Tomcat 8.0\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;%CommonProgramFiles%\Microsoft Shared\Windows Live;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Program Files\Sublime Text 2;C:\Program Files\MySQL\MySQL Server 5.5\bin;C:\Program Files\Common Files\Microsoft Shared\Windows Live;.
    18-Nov-2013 16:34:57.315 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
    18-Nov-2013 16:34:57.378 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
    18-Nov-2013 16:34:57.378 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"]
    18-Nov-2013 16:34:57.409 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
    18-Nov-2013 16:34:57.409 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 553 ms
    18-Nov-2013 16:34:57.440 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service Catalina
    18-Nov-2013 16:34:57.440 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.0.0-RC5
    18-Nov-2013 16:34:57.471 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive C:\Program Files (x86)\Apache Software Foundation\Tomcat 8.0\webapps\sample.war
    18-Nov-2013 16:34:58.048 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory C:\Program Files (x86)\Apache Software Foundation\Tomcat 8.0\webapps\docs
    18-Nov-2013 16:34:58.204 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory C:\Program Files (x86)\Apache Software Foundation\Tomcat 8.0\webapps\helloworld
    18-Nov-2013 16:34:58.204 SEVERE [localhost-startStop-1] org.apache.tomcat.util.descriptor.web.WebXmlParser.parseWebXml Parse error in application web.xml file at file:/C:/Program%20Files%20(x86)/Apache%20Software%20Foundation/Tomcat%208.0/webapps/helloworld/WEB-INF/web.xml
     com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 1 of 1-byte UTF-8 sequence.
    	at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.invalidByte(Unknown Source)
    	at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.read(Unknown Source)
    	at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.load(Unknown Source)
    	at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.skipDeclSpaces(Unknown Source)
    	at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(Unknown Source)
    	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
    	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
    	at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
    	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
    	at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
    	at org.apache.tomcat.util.digester.Digester.parse(Digester.java:1449)
    	at org.apache.tomcat.util.descriptor.web.WebXmlParser.parseWebXml(WebXmlParser.java:119)
    	at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1105)
    	at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:769)
    	at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:305)
    	at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
    	at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
    	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5166)
    	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:726)
    	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:702)
    	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:698)
    	at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1119)
    	at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1760)
    	at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    	at java.util.concurrent.FutureTask.run(Unknown Source)
    	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    	at java.lang.Thread.run(Unknown Source)
    
    18-Nov-2013 16:34:58.220 SEVERE [localhost-startStop-1] org.apache.catalina.startup.ContextConfig.configureStart Marking this application unavailable due to previous error(s)
    18-Nov-2013 16:34:58.220 SEVERE [localhost-startStop-1] org.apache.catalina.core.StandardContext.startInternal Error getConfigured
    18-Nov-2013 16:34:58.220 SEVERE [localhost-startStop-1] org.apache.catalina.core.StandardContext.startInternal Context [/helloworld] startup failed due to previous errors
    18-Nov-2013 16:34:58.220 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory C:\Program Files (x86)\Apache Software Foundation\Tomcat 8.0\webapps\manager
    18-Nov-2013 16:34:58.454 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory C:\Program Files (x86)\Apache Software Foundation\Tomcat 8.0\webapps\ROOT
    18-Nov-2013 16:34:58.641 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
    18-Nov-2013 16:34:58.688 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"]
    18-Nov-2013 16:34:58.735 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 1318 ms

Similar Threads

  1. Tomcat and servlets beginner question
    By iparry in forum New To Java
    Replies: 2
    Last Post: 03-24-2012, 01:49 AM
  2. Servlets class not teaching servlets
    By tsky in forum Java Servlet
    Replies: 5
    Last Post: 04-26-2011, 10:47 PM
  3. simple question about servlets
    By kulangotski in forum Java Servlet
    Replies: 2
    Last Post: 01-06-2011, 09:50 AM
  4. question on servlets
    By Minu in forum Java Servlet
    Replies: 4
    Last Post: 01-16-2009, 10:21 AM
  5. Probably a really simple question...
    By ibanez270dx in forum New To Java
    Replies: 0
    Last Post: 11-16-2007, 01:27 AM

Posting Permissions

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