aspose file tools*
The moose likes Beginning Java and the fly likes compilation error while running simple servlet code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "compilation error while running simple servlet code" Watch "compilation error while running simple servlet code" New topic
Author

compilation error while running simple servlet code

Jenny raj
Ranch Hand

Joined: May 19, 2005
Posts: 57
package hall;

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

public class HelloWorldServlet extends HttpServlet
{
public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException
{
PrintWriter out = response.getWriter();
out.println("Hello World");
}
}


i tried executing the above servlet after installing j2ee 1.4,

while compiling the above program i am getting the follwing error message


HelloWorldServlet.java:4: package javax.servlet does not exist
import javax.servlet.*;
^
HelloWorldServlet.java:5: package javax.servlet.http does not exist
import javax.servlet.http.*;
^
HelloWorldServlet.java:7: cannot resolve symbol
symbol : class HttpServlet
location: class hall.HelloWorldServlet
public class HelloWorldServlet extends HttpServlet
^
HelloWorldServlet.java:9: cannot resolve symbol
symbol : class HttpServletRequest
location: class hall.HelloWorldServlet
public void doGet(HttpServletRequest request,HttpServletResponse response) thr
ows ServletException, IOException
^
HelloWorldServlet.java:9: cannot resolve symbol
symbol : class HttpServletResponse
location: class hall.HelloWorldServlet
public void doGet(HttpServletRequest request,HttpServletResponse response) thr
ows ServletException, IOException
^
HelloWorldServlet.java:9: cannot resolve symbol
symbol : class ServletException
location: class hall.HelloWorldServlet
public void doGet(HttpServletRequest request,HttpServletResponse response) thr
ows ServletException, IOException

^
6 errors



what could be the problem?where i am going wrong ?
Scott Dunbar
Ranch Hand

Joined: Sep 23, 2004
Posts: 245
You will have to include the J2EE jars in your classpath somehow. You can start on the command line with something like:

javac -classpath ,;/path/to/j2ee/jar/file.jar HelloWorldServlet.java

but soon you'll want more and more on the classpath. If you're just experimenting then you can continue with the command line. Otherwise you may want to consider a build tool such as ant to help you manage your build environment easier.


<a href="http://forums.hotjoe.com/forums/list.page" target="_blank" rel="nofollow">Java forums using Java software</a> - Come and help get them started.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Our servlets faq has a section on compiling servlets (with links to the JIG beginner faq on classpaths).
http://faq.javaranch.com/view?ServletsFaq

If you're using Tomcat, all the dependencies needed for compilation can be found in the {tomcat install}/common/lib/servlet-api.jar file.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Jenny raj
Ranch Hand

Joined: May 19, 2005
Posts: 57
i have no idea abt tomcat,
do i have to install it to run a servlet?
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14156
    
  19

If you have installed the J2EE SDK then you don't need to download and install Tomcat - you can just deploy and run your servlet in the J2EE reference implementation application server.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

For aun's j2ee sdk this will probably be j2ee.jar.
If you only want to practice servlets, you could just use Tomcat instead of the full j2ee.


[My Blog]
All roads lead to JavaRanch
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: compilation error while running simple servlet code