We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Servlet does not compile in Eclipse 3.1

latimercm4
latimercm4 asked
on
Medium Priority
877 Views
Last Modified: 2008-01-09
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.
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2006

Commented:
please post your web.xml and your sevlet code

Author

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.

Commented:
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



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

     wouldn't it be /classes folder?
>> 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
>>It will be in web-inf/classes/org.eclipse.Tom_sub folder.
     
     should be web-inf/classes/org/eclipse/Tom_sub

Author

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.
set your compilation path to <web-root>/web-inf/classes or after compilation, copy them into web-inf/classes.

Author

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.
<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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Thanks for your rate.  You must've done a lot of tests. Hope you learned sth.

:)

Author

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.
:)
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.