Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie: cant compile servlets or jsps

Status
Not open for further replies.

taylorj

Programmer
Oct 21, 2003
14
IE
Sorry, i cant compile servlets or jsps. I have tomcat5.0 installed am using j2sdk but i get errors like javax.servlet does not exist. I cannot find servlet.jar in my tomcat installation; i read it was in %catalina_home%in tomcat4.x. What i'm asking is what do i need to compile a servlet? How do i do it? Very grateful to any replies..
 
No there's no j2ee.jar and no servlet.jar in %CATALINA_HOME%\common\lib; the nearest thing here is servlet-api.jar. This is the output i get when i try to compile HelloServlet.java;
Code:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class HelloServlet extends HttpServlet {

	  public void doGet(HttpServletRequest request,HttpServletResponse response)
	  		throws ServletException, IOException {
	    response.setContentType("text/html");

	    PrintWriter out = response.getWriter();
	    String docType =
	      &quot;<!DOCTYPE HTML PUBLIC \&quot;-//W3C//DTD HTML 4.0 &quot; +
	      &quot;Transitional//EN\&quot;>\n&quot;;
	    out.println(docType +
	                &quot;<HTML>\n&quot; +
	                &quot;<HEAD><TITLE>Hello</TITLE></HEAD>\n&quot; +
	                &quot;<BODY BGCOLOR=\&quot;#FDF5E6\&quot;>\n&quot; +
	                &quot;<H1>Hello</H1>\n&quot; +
	                &quot;</BODY></HTML>&quot;);
	  }
}

Output from compiler

HelloServlet.java:2: package javax.servlet does not exist
import javax.servlet.*;
^
HelloServlet.java:3: package javax.servlet.http does not exist
import javax.servlet.http.*;
^
HelloServlet.java:13: cannot resolve symbol
symbol : class HttpServlet
location: class HelloServlet
public class HelloServlet extends HttpServlet {
^
HelloServlet.java:15: cannot resolve symbol
symbol : class HttpServletRequest
location: class HelloServlet
public void doGet(HttpServletRequest request,HttpServletResponse response)


My environment variables are
CLASSPATH=.
PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system\WBEM;C:\ProgramFiles\CommonFiles\AdaptecShared\System;C:\j2sdk1.4.2_02\bin
CATALINA_HOME=C:\PROGRA~1\APACHE~1\TOMCAT~1.0
ANT_HOME=C:\PROGRA~1\APACHE~1\APACHE~1.4
JAVA_HOME=C:\j2sdk1.4.2_02
 
Its allright folks, no need to rush with suggestions [:), i put %catalina_home%\common\lib\servlet-api.jar onto the classpath and i managed to compile me servlet.. now i've got to deploy it and test it in the browser, wish me luck.
 
You need to include TOMCAT_HOME/common/lib/servlet.jar in your class path.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top