latimercm4
asked on
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.
I have Eclipse 3.1, tomcat 3.0.19 and JDK1.5.0_06.
please post your web.xml and your sevlet code
ASKER
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("t ext/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>HelloWorldS ervlet</se rvlet-clas s>
</servlet>
<servlet-mapping>
<servlet-name>HelloServlet </servlet- name>
<url-pattern>/hello</url-p attern>
</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.
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("t
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-class>HelloWorldS
</servlet>
<servlet-mapping>
<servlet-name>HelloServlet
<url-pattern>/hello</url-p
</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.
I hope this is a typo
>>tomcat 3.0.19
moreover,
<servlet>
<servlet-name>HelloServlet </servlet- name>
<servlet-class>HelloWorldS ervlet</se rvlet-clas s>
</servlet>
should be
<servlet>
<servlet-name>HelloServlet </servlet- name>
<servlet-class>org.eclipse .Tom_sub.H elloWorldS ervlet</se rvlet-clas s>
</servlet>
fargo
>>tomcat 3.0.19
moreover,
<servlet>
<servlet-name>HelloServlet
<servlet-class>HelloWorldS
</servlet>
should be
<servlet>
<servlet-name>HelloServlet
<servlet-class>org.eclipse
</servlet>
fargo
>> I cannot locate a HelloWorldServlet.class in /class folder
wouldn't it be /classes folder?
wouldn't it be /classes folder?
>> I cannot locate a HelloWorldServlet.class in /class folder
It will be in web-inf/classes/org.eclips e.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.eclips
& 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.eclips e.Tom_sub folder.
should be web-inf/classes/org/eclips e/Tom_sub
should be web-inf/classes/org/eclips
ASKER
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.
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.
ASKER
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.
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.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Thanks for your rate. You must've done a lot of tests. Hope you learned sth.
:)
:)
ASKER
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.
:)
Have a wonderful day.
:)