• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error in compliing Servlet

 
Nilesh Raje
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Freinds,

Can any one tell me y this program is not running. This is from HFSJ.


package com.example.web;

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

public class BeerSelect extends HttpServlet{


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

response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("Beer Selection Advice<br>");
String c=request.getParameter("color");

out.println("<br> Got Beer Color :"+c);

}

}



C:\SCWCD-CX310081\MyProjects\beerv1>javac -classpath /jakarta-tomcat-5.5.11/comm
on/lib/servlet-api.jar:classes:. -d classes src/com/example/web/BeerSelect.java
src/com/example/web/BeerSelect.java:3: package javax.servlet does not exist
import javax.servlet.*;
^
src/com/example/web/BeerSelect.java:4: package javax.servlet.http does not exist

import javax.servlet.http.*;
^
src/com/example/web/BeerSelect.java:7: cannot find symbol
symbol: class HttpServlet
public class BeerSelect extends HttpServlet{
^
src/com/example/web/BeerSelect.java:10: cannot find symbol
symbol : class HttpServletRequest
location: class com.example.web.BeerSelect
public void doPost(HttpServletRequest request, HttpServletResponse response)
^
src/com/example/web/BeerSelect.java:10: cannot find symbol
symbol : class HttpServletResponse
location: class com.example.web.BeerSelect
public void doPost(HttpServletRequest request, HttpServletResponse response)
^
src/com/example/web/BeerSelect.java:11: cannot find symbol
symbol : class ServletException
location: class com.example.web.BeerSelect
throws ServletException, IOException {
^
6 errors
 
Nathaniel Stoddard
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks like you haven't included the servlet portion of the J2EE platform on your classpath during compilation. There's a FAQ out here on JavaRanch somewhere (I think) that details how to setup your classpath, but unfortunately I can't point it to you. Searching the forum may help you find out where that is.
 
Amit Saini
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Theres a file that comes in Tomcat\Common\Lib called servlet-api.jar.
Add this file to the classpath and it should be ok.
 
Cai DongShan
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please try
javac -classpath /jakarta-tomcat-5.5.11/common/lib/servlet-api.jar:classes:. -d classes src/com/example/web/BeerSelect.java
(change : to
 
Cai DongShan
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, didn't change, please change : to ;
javac -classpath /jakarta-tomcat-5.5.11/common/lib/servlet-api.jar;classes;. -d classes src/com/example/web/BeerSelect.java
 
Don Bryant
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The back-slashes between MyProjects and beerv1 suggests that this is on a windows machine. So, surely, all forward-slashes should be swapped for back-slashes and the colon( between jar and classes should be exchanged for a semi-colon( . I dont know what the colon and stop (:.) after classes do but when I ploughed through this book I worked this command on an XPHome machine without them.
Stop press: See Nicky Eng's entry for Sept 18. She's got it.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic