• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Error in compliing Servlet

 
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
His brain is the size of a cherry pit! About the size of this ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic