Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 839
  • Last Modified:

Servlet does not compile in Eclipse 3.1

I am a newbie.  I can produce the html version of hello world but when I try the servlet version I get the http 404 status error message.  I cannot locate a HelloWorldServlet.class in /class folder.  I also see "the serializable class HelloworldServlet does not declare a static final serialVersionUD field of long type.
I have Eclipse 3.1, tomcat 3.0.19 and JDK1.5.0_06.
0
latimercm4
Asked:
latimercm4
1 Solution
 
bloodredsunCommented:
please post your web.xml and your sevlet code
0
 
latimercm4Author Commented:
HeloWorldServlet.java
package org.eclipse.Tom_sub;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;


public class HelloWorldServlet  extends HttpServlet{
      
      public void doGet(HttpServletRequest request,
                            HttpServletResponse response )
      throws IOException, ServletException {
            response.setContentType("text/html");
            PrintWriter out = response.getWriter();
            out.println("<html>");
            out.println("<body>");
            out.println("<h1>Hello World</html>");
            out.println("</body>");
            out.println("</html>");
      }
      
}

web.xml

<!DOCTYPE web-app
  PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
  "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>

  <servlet>
    <servlet-name>HelloServlet</servlet-name>
    <servlet-class>HelloWorldServlet</servlet-class>
  </servlet>

  <servlet-mapping>
    <servlet-name>HelloServlet</servlet-name>
    <url-pattern>/hello</url-pattern>
  </servlet-mapping>

</web-app>

I'm believe it has something to do with how I have Eclipse set up.  I do not have a classpath variable defined.  I do not see any error anywhere.  I checked to see if there was a tomcat.log file.

0
 
fargoCommented:
I hope this is a typo
>>tomcat 3.0.19

moreover,
<servlet>
    <servlet-name>HelloServlet</servlet-name>
    <servlet-class>HelloWorldServlet</servlet-class>
  </servlet>

should be

<servlet>
    <servlet-name>HelloServlet</servlet-name>
    <servlet-class>org.eclipse.Tom_sub.HelloWorldServlet</servlet-class>
  </servlet>

fargo



0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
actonwangCommented:
>> I cannot locate a HelloWorldServlet.class in /class folder

     wouldn't it be /classes folder?
0
 
KuldeepchaturvediCommented:
>> I cannot locate a HelloWorldServlet.class in /class folder

It will be in web-inf/classes/org.eclipse.Tom_sub folder.
& also I hope you are typing http://localhost:8080/yourwebapp/hello to invoke your servlet & not
http://localhost:8080/yourwebapp/servlet/HelloWorldServlet
0
 
actonwangCommented:
>>It will be in web-inf/classes/org.eclipse.Tom_sub folder.
     
     should be web-inf/classes/org/eclipse/Tom_sub
0
 
latimercm4Author Commented:
I searched my drive and could not locate the file.  I searched Google and found something that indicated that I needed to have a file in order for the servlet to compile.  I modified my workspace and then the class compiled.  

I am going to run it in IE as http://localhost:8080/Tom1/HelloWorldServlet and see if it works...and then I will try the hello to see if one of them will work.
0
 
actonwangCommented:
set your compilation path to <web-root>/web-inf/classes or after compilation, copy them into web-inf/classes.
0
 
latimercm4Author Commented:
The "hello" works.  Is there a reason why I do not see the /WEB-INF/classes all of the time?

where do I modify the compilation path.  I was following a tutorial from javaboutique.  It indicated that if I modified the Tomcat/conf/web.xml using invoker and servlet mapping that I can run this using HelloWorldServlet class name.  On my workstation I get the status 404 message when I enter http://localhost:8080/Tom1/servlet/HelloWorldServlet (and then press enter).  Am I missing something here?  Or is Eclipse not properly set up?  Thank you for your help.
0
 
actonwangCommented:
<web root>/WEB-INF/classes needs to be created by you if you want it.

ok, you are using invoker, you have to give invoker a full class name: say you want to invoke class
package1.class1 then you have to do : http://.../Tom1/servlet/package1/class1

0
 
actonwangCommented:
Thanks for your rate.  You must've done a lot of tests. Hope you learned sth.

:)
0
 
latimercm4Author Commented:
Thank you.  I have become very frustrated.  Just trying to build a web application within Eclipse with struts without anything to help guide me has been very frustrating.  I've been using Java boutique as a guide...do you know of anything else I can use?  Thank you again for your help.  I still have not gotten all the kinks out but I am further along and I know that I will have more questions as I go along.

Have a wonderful day.
:)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now