Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception during compiling servlet

 
Brijesh shah
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All;

I have installed jdk1.5 and tomcat5.5 in my computer, While compiling following code i get error as mentioned below..I have paste the servlet.jar file in Tomcat 5.5\common\lib...I do not understand what can be the problems..Please help me out on this..

package com.example.web;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class BeerSelect extends HttpServlet{
public void doPost(HttpServletRequest req, HttpServletResponse res)throws IOException, ServletException{
res.setContentType("Text/html");
PrintWriter out = res.getWriter();
out.println("Beer Selection Advice<br>");
String c = req.getParameter("color");
out.println("<br>Got beer color " + c);
}
}


ERROR>>
BeerSelect.java:2: package javax.servlet does not exist
import javax.servlet.*;
BeerSelect.java:3: package javax.servlet.http does not exist
import javax.servlet.http.*;
cannot find symbol for following
BeerSelect.java:3: package javax.servlet.http does not exist
public void doPost(HttpServletRequest req, HttpServletResponse res)throws IOException, ServletException{public void doPost(HttpServletRequest req, HttpServletResponse res)throws IOException, ServletException{


Hope to hear from you soon.

Thanks in advance.

Best Regards,
Brijesh Shah
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does your classpath contain the servlet.jar?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rahul Bhattacharjee:
Does your classpath contain the servlet.jar?


It's servlet-api.jar.
The jar file can be found in tomcat/common/lib.

See: CompilingServlets from our Servlets FAQ for more information.

I'm going to move this to our Java In General (Beginner) forum where javac and classpath issues are discussed.
 
Brijesh shah
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Servlet.jar file is present in my tomcat/common/lib path..I have installed jdk1.5 in which there is no need to set the path..I am using editplus in which I have configured the tools for compile and run..For servlet I wrote java code as mentioned above..After writing that code when I am compiling it I found the error as mentioned above...I am preparing for SCWCD..I am referring Head First book in which i was doing practice as given in the book and stuck in this scenario.

So i don�t understand what can be the problem..

Hope to hear from you soon

--Brijesh Shah
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Classpath is place where the compiler looks for classes.This is required for compilation unless you do not have any dependency.
 
Brijesh shah
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

In editPlus I have created the classpath for java compilation as C:\Program Files\Java\jdk1.5.0\bin\javac.exe...I hope this is correct for compiling servlet code also.

Please let me know the solution..
Regards,
Brijesh

[ July 17, 2007: Message edited by: Brijesh shah ]
[ July 17, 2007: Message edited by: Brijesh shah ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic