• Post Reply Bookmark Topic Watch Topic
  • New Topic

error on first servlet program  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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???
 
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://www.coderanch.com/how-to/java/CompilingServlets
 
Ranch Hand
Posts: 78
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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....
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!