aspose file tools
The moose likes Beginning Java and the fly likes error on first servlet program Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "error on first servlet program" Watch "error on first servlet program" New topic
Author

error on first servlet program

Aman Adhikari
Greenhorn

Joined: Dec 03, 2011
Posts: 2
import java.io.*;
import javax.servlet.*;
import javax.servlet.http;
public class First extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("Hello world of servlets!!!");
}

public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {

}
}


// i typed above got and got error listed below

G:\Servlets\Test\src\First.java:2: package javax.servlet does not exist
import javax.servlet.*;
^
G:\Servlets\Test\src\First.java:3: package javax.servlet does not exist
import javax.servlet.http;
^
G:\Servlets\Test\src\First.java:4: cannot find symbol
symbol: class HttpServlet
public class First extends HttpServlet {
^
G:\Servlets\Test\src\First.java:5: cannot find symbol
symbol : class HttpServletRequest
location: class First
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
^
G:\Servlets\Test\src\First.java:5: cannot find symbol
symbol : class HttpServletResponse
location: class First
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
^
G:\Servlets\Test\src\First.java:11: cannot find symbol
symbol : class HttpServletRequest
location: class First
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
^
G:\Servlets\Test\src\First.java:11: cannot find symbol
symbol : class HttpServletResponse
location: class First
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
^
7 errors

Tool completed with exit code 1





// can i get your help guyz???
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56185
    
  13

You need to include the server API jar from your container in your build.

I've moved this to the Beginning Java forum where learning how to compile is discussed.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

http://www.coderanch.com/how-to/java/CompilingServlets


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
Avinash Ga
Ranch Hand

Joined: Aug 13, 2011
Posts: 70

have a servlet-api.jar in your classpath while compiling and deploy the compiled servlet in any of the container.

also have a look at.

http://www.coderanch.com/t/364854/Servlets/java/where-download-servlet-api-jar

Best Wishes....


Avinash G.A
OCP Java SE 6 Programmer, OCP Java EE 5 Web Component Developer, OCE Java EE 6 Web Services Developer, VMware Certified Core Spring 3.x Developer
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: error on first servlet program
 
Similar Threads
error with compiling servlet
java don't compile my servlet.
Java doesn't know where to find servlet packages
Problems installing Tomcat/XP
How to solve this one