aspose file tools*
The moose likes Beginning Java and the fly likes Exception during compiling servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Exception during compiling servlet " Watch "Exception during compiling servlet " New topic
Author

Exception during compiling servlet

Brijesh shah
Ranch Hand

Joined: Mar 16, 2007
Posts: 90
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

Joined: Nov 29, 2005
Posts: 2308
Does your classpath contain the servlet.jar?


Rahul Bhattacharjee
LinkedIn - Blog
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Brijesh shah
Ranch Hand

Joined: Mar 16, 2007
Posts: 90
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

Joined: Nov 29, 2005
Posts: 2308
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

Joined: Mar 16, 2007
Posts: 90
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 ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Exception during compiling servlet