Two Laptop Bag*
The moose likes Servlets and the fly likes Compiling servlet file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Compiling servlet file" Watch "Compiling servlet file" New topic
Author

Compiling servlet file

Varun Nayudu
Ranch Hand

Joined: Jun 26, 2006
Posts: 157
Hi guys i have just downloaded Editplus and want to know how to compile a servlet file .Please tell what needs to be done .I am getting a compiler error when i try to compile a simple servlet file


-------------------servlet file -------------------
package web.servlet;

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

public class ser extends HttpServlet
{
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws IOException ,ServletException{
System.out.println("------ in the ser.java servldet ---------");
}
}

------------------End of servlet file ----------------

---------- Java Compiler ----------
D:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\XYZ\WEB-INF\classes\web\servlet\ser.java:3: package javax.servlet does not exist
import javax.servlet.*;
^
D:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\XYZ\WEB-INF\classes\web\servlet\ser.java:4: package javax.servlet.http does not exist
import javax.servlet.http.*;
^
D:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\XYZ\WEB-INF\classes\web\servlet\ser.java:7: cannot find symbol
symbol: class HttpServlet
public class ser extends HttpServlet
^
D:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\XYZ\WEB-INF\classes\web\servlet\ser.java:9: cannot find symbol
symbol : class HttpServletRequest
location: class web.servlet.ser
public void doGet(HttpServletRequest request,HttpServletResponse response)
^
D:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\XYZ\WEB-INF\classes\web\servlet\ser.java:9: cannot find symbol
symbol : class HttpServletResponse
location: class web.servlet.ser
public void doGet(HttpServletRequest request,HttpServletResponse response)
^
D:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\XYZ\WEB-INF\classes\web\servlet\ser.java:10: cannot find symbol
symbol : class ServletException
location: class web.servlet.ser
throws IOException ,ServletException{
^
6 errors

Output completed (1 sec consumed)


Please advice me what all needs to be done


SCJP 1.5, SCWCD 1.5
Vinoth Thirunavukarasu
Ranch Hand

Joined: Dec 18, 2008
Posts: 164

Hello,
I think you haven't set the class path for javax.servlet package. To compile a servlet you must specify class path.


Java Best Practices
Linux Best Practices
Amortization Calculator

Varun Nayudu
Ranch Hand

Joined: Jun 26, 2006
Posts: 157
I also have Gel and it dosnt give me any compiler error when i compile the servlet file i dont know where to set the classpath for Editplus

I want to know how to compile a servlet file in edit plus
Aum Tao
Ranch Hand

Joined: Feb 14, 2006
Posts: 210
You should have a look at ServletsFAQ

If it's an IDE specific question, you are better off posting it in the IDE forum.
[ December 20, 2008: Message edited by: Prateek Parekh ]

SCJP 1.4 85%
XinShou ShangLu
Greenhorn

Joined: Sep 26, 2008
Posts: 9
Firsty,I never compile any java files in Editplus.

I think you must use 'servlet-api.jar'.This file should be in the '%tomcat%\lib\'.

You can specify like this : (I guess your tomcat directory is 'D:\Program Files\Apache Software Foundation\Tomcat 5.0\' LOL)
-classpath D:\Program Files\Apache Software Foundation\Tomcat 5.0\lib\servlet-api.jar
[ December 23, 2008: Message edited by: XinShou ShangLu ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Compiling servlet file
 
Similar Threads
package does not exist problem
unable to compile servlet
J2EE newbie; Tomcat Installation Problems: First Servlet
How to include jars in command line classpath?
fix this error