6 Replies Latest reply: Nov 9, 2012 10:25 AM by WIP RSS

    Help with Eclipse , Java Servlet and Tomcat

    WIP
      hi,

      I have written my first servlet.

      apache-tomcat-7.0.32
      Eclipse is eclipse-jee-juno-SR1 latest from the website.
      configured the tomcat with eclipse
      I have included the servlet-api.jar ,hence class is compiled.

      Bit stuck with the execution of servlet .

      How to configure eclipse to get my servlet file to run

      My eclipse project is ---->PROJECT1
      my package is --->org.eclipse.pkg1

      tomcat is up and running

      class file is in bookworkspace\pkg1\bin\org\eclipse\pkg1

      java source file is in bookworkspace\pkg1\src\org\eclipse\pkg1

      when http://localhost:8080/myservlet ........tomcat says resource not found...

      Pls suggest...

      rgds
      s
        • 1. Re: Help with Eclipse , Java Servlet and Tomcat
          gimbal2
          - is your application really deployed as the root-application? I would expect the URL to be something like 'localhost:8080/somewebsitename/myservlet'
          - did you add either a @WebServlet annotation to the servlet, or configured it in the web.xml?
          - you're not making a typo right? Check the url against the url-mapping

          Edited by: gimbal2 on Nov 9, 2012 1:05 AM
          • 2. Re: Help with Eclipse , Java Servlet and Tomcat
            WIP
            - is your application really deployed as the root-application? I would expect the URL to be something like 'localhost:8080/somewebsitename/myservlet'
            This is a one-off servlet. I thought eclipse when configured with Tomcat will take care of this.
            How to i tell eclise to deploy this as root application in tomcat ?
            What is the /somewebsitename/ here ?

            - did you add either a @WebServlet annotation to the servlet, or configured it in the web.xml?
            No I have not added @WebServlet in myservlet.java file in eclipse

            I have not configured web.xml .

            What is the best option in a professional environment ? @webservlet or web.xml ?
            - you're not making a typo right? Check the url against the url-mapping
            I am not making any typo.

            Thanks
            S
            • 3. Re: Help with Eclipse , Java Servlet and Tomcat
              gimbal2
              WIP  wrote:
              This is a one-off servlet. I thought eclipse when configured with Tomcat will take care of this.
              How to i tell eclise to deploy this as root application in tomcat ?
              An excellent question to Google.
              What is the /somewebsitename/ here ?
              The context name.
              No I have not added @WebServlet in myservlet.java file in eclipse

              I have not configured web.xml .
              So you're just writing code without reading how the stuff works first?

              >
              What is the best option in a professional environment ? @webservlet or web.xml ?
              @WebServlet annotation since you're using Tomcat 7.
              I am not making any typo.
              Generally you let other people be the judge of that by posting code and/or configuration files. But I believe you since you completely missed any kind of configuration.
              • 4. Re: Help with Eclipse , Java Servlet and Tomcat
                939520
                If you can't get one tutorial to work and you are really stuck, it may be time to try another tutorial. It might get you un-stuck.

                A search of Google for this:
                "tomcat 7" eclipse servlet simple example
                yields this:
                http://www.srccodes.com/p/article/3/Tomcat-Hello-World-Servlet-using-Eclipse-IDE
                which looks promising (although I haven't tried it).
                • 5. Re: Help with Eclipse , Java Servlet and Tomcat
                  WIP
                  Many Thanks for your replies.

                  the issue here is about eclipes and tomcat.

                  When I start/stop tomcat via cmd prompt

                  1)myservlet works as desired
                  2)hello.jsp (or index.jsp) also works as desired.

                  Then I stop tomcat via cmd and start it via eclipse.

                  I get no error in eclipse console while starting and it completes without errors.
                  Then I try running the myservlet or hello.jsp through browser they won't work ....nor does index.jsp homepage work...means tomcat is not working

                  Below is the output of eclipse console
                  09-Nov-2012 15:14:33 org.apache.catalina.core.AprLifecycleListener init
                  INFO: The APR based Apache Tomcat Native library which allows optimal performance 
                  in production environments was not found on the 
                  java.library.path: C:\Java\jdk1.6.0_26\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;
                  C:/Java/jdk1.6.0_26/bin/../jre/bin/server;
                  C:/Java/jdk1.6.0_26/bin/../jre/bin;
                  C:/Java/jdk1.6.0_26/bin/../jre/lib/amd64;
                  C:\Java\jdk1.6.0_26\bin;
                  C:\app\sal\product\11.2.0\dbhome_1\bin;
                  C:\Program Files (x86)\HP SimplePass 2011\x64;
                  C:\Program Files (x86)\HP SimplePass 2011\;;
                  C:\Program Files\Common Files\Microsoft Shared\Windows Live;
                  C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;
                  C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;
                  C:\Windows\System32\WindowsPowerShell\v1.0\;
                  C:\Program Files (x86)\Windows Live\Shared;
                  C:\Program Files (x86)\Intel\Services\IPT\;
                  C:\Oracle\Middleware\Oracle_BI1\products\Essbase\EssbaseServer\bin;
                  C:\Oracle\Middleware\Oracle_BI1\bin;
                  C:\Oracle\Middleware\Oracle_BI1\opmn\bin;
                  C:\Oracle\Middleware\Oracle_BI1\opmn\lib;
                  C:\Oracle\Middleware\Oracle_BI1\perl\bin;
                  c:\obi\Oracle_BI1\products\Essbase\EssbaseServer\bin;
                  c:\obi\Oracle_BI1\bin;c:\obi\Oracle_BI1\opmn\bin;
                  c:\obi\Oracle_BI1\opmn\lib;
                  c:\obi\Oracle_BI1\perl\bin;
                  C:\Users\sal\Downloads\eclipse-jee-juno-SR1-win32-x86_64\eclipse;;.
                  
                  
                  09-Nov-2012 15:14:33 org.apache.coyote.AbstractProtocol init
                  INFO: Initializing ProtocolHandler ["http-bio-8080"]
                  09-Nov-2012 15:14:33 org.apache.coyote.AbstractProtocol init
                  INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
                  09-Nov-2012 15:14:33 org.apache.catalina.startup.Catalina load
                  INFO: Initialization processed in 591 ms
                  09-Nov-2012 15:14:33 org.apache.catalina.core.StandardService startInternal
                  INFO: Starting service Catalina
                  09-Nov-2012 15:14:33 org.apache.catalina.core.StandardEngine startInternal
                  INFO: Starting Servlet Engine: Apache Tomcat/7.0.32
                  09-Nov-2012 15:14:34 org.apache.coyote.AbstractProtocol start
                  INFO: Starting ProtocolHandler ["http-bio-8080"]
                  09-Nov-2012 15:14:34 org.apache.coyote.AbstractProtocol start
                  INFO: Starting ProtocolHandler ["ajp-bio-8009"]
                  09-Nov-2012 15:14:34 org.apache.catalina.startup.Catalina start
                  INFO: Server startup in 356 ms
                  Please suggest.

                  Thanks
                  s
                  • 6. Re: Help with Eclipse , Java Servlet and Tomcat
                    WIP
                    your above link is also nice.....

                    But fails at the last step...When runing the servlet via eclipse :(