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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

javax.servlet does not exist error

Status
Not open for further replies.

ALSav

Technical User
Feb 21, 2001
66
GB
Hi,

I am on day 1 of trying out servlets. I am using j2sdk1.4.1_05 and resin-ee-3.0.6. The resin seem to be set up OK according to my tutorial and PATH, CLASSPATH and JAVA_HOME have all been set.
My problem arises when I try to compile a simple HelloServlet.java that has been downloaded form the Sun website.

I always get the error "javax.servlet does not exist, import javax.servlet.*"

Does javax.servlet not come with j2sdk1.4.1_05 and where do I obtain it.

The book I am using makes no mention anywhere of this problem. I am following the tutorial in 'Core Servlets and JavaServer Pages' by Marty Hall and Larry Brown (excellent book) and the code for the HelloServlet is

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;);
}
}

simple enough but I can't get over the first hurdle.

Grateful for any help

regards

ALSav
 
In your resin installation there should be a file called servlet.jar - add this to your CLASSPATH (full path and jar file name, so set CLASSPATH=%CLASSPATH%;C:\a\b\c\servlet.jar)

If you cannot find this jar file, you should be able to find it on the sun site for download
 
Thanks sedj,

I already have that one set in the CLASSPATH although according to the tutorial I am following, in this version of resin it is called jsdk-24.jar and not servlet.jar

regards
ALsav
 
Are you using the javac.exe compiler from the console command line to compile your class, or an IDE ?

If an IDE, then you'll need to add that jar file to the IDE's classpath aswell.

If via the command line, then check you are defintely setting the CLASSPATH like this :

set CLASSPATH=%CLASSPATH%;C:\myjars\somewghere\jsdk-24.jar

and check that there are no typos etc.

To check that the javax.servlet.* packages are present in that jar file, either type

jar -tvf jsdk-24.jar (this views the contents) or open with WinZip or similar. Check that the correct packages are there.
 
Hi Sedj,

I still get errors when I compile with the MS-DOS prompt and I still cannot see anything wrong with the variables.

I have tried it through an IDE (IntelliJ IDEA), set all the variables and it seems to recognise javax.servlet OK. The only problem now is that this IDE is integrated with Tomcat and not Resin so I may abandon Resin and switch to Tomcat. (Although I don't think it's the server that's the problem but if I can get something to work I may just stick with it).

thanks for your help

regards

ALSav

 
Did you try this :

To check that the javax.servlet.* packages are present in that jar file, either type

jar -tvf jsdk-24.jar (this views the contents) or open with WinZip or similar. Check that the correct packages are there.
 
Hi sedj,

The file is definitely there in the in my C:\servers\resin-ee-3.0.6\lib as expected. Currently I am compiling using the IntelliJ IDEA IDE that is integrated to Tomcat and uses Tomcat's servlet.jar file. Then I am running the servlet using Resin because I am having problems with Tomcat's (5.0.18)servlet invoker so between the two I am managing to acheive something.

thanks for you help
regards
ALSav
 
What problems with the servlet invoker in Tomcat ?

 
To enable the invoker servlet the instructions are to uncomment the following lines in the conf/web.xml file in Tomcat.
<servlet-mapping>
<servlet-name>invoker</servlet-name>
<url-pattern>/servlet/*</url-pattern>
</servlet-mapping>

When I remove the comment markers, I get a whole bunch of errors in the consol window and the typical url for testing a servlet e.g. takes me nowhere. (URL works OK in resin (using port 80)and I am not running them simultaneously so there are no port conflicts and I put resin on 80 to make sure).

The rlease notes for Tomcat 5.0.18 state the following
-------------
Starting with Tomcat 4.1.12, the invoker servlet is no longer available by default in all webapps. Enabling it for all webapps is possible by editing $CATALINA_HOME/conf/web.xml to uncomment the &quot;/servlet/*&quot; servlet-mapping definition.

Using the invoker servlet in a production environment is not recommended and is unsupported.
--------------------

Hence I use Tomcat servlet.jar to compile in IntelliJ IDEA but Resin to run the servlet.
Still get javax.servlet errors compiling via the MS DOS prompt.

Getting results though even if it is a bit convoluted.

regards

ALSav
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top