aspose file tools*
The moose likes Servlets and the fly likes Servlet compiler error 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 » Servlets
Bookmark "Servlet compiler error" Watch "Servlet compiler error" New topic
Author

Servlet compiler error

Nicholas Carrier
Ranch Hand

Joined: Apr 14, 2005
Posts: 78
Ever feel like you have the same problem as a million other people, yet you can't figure out how your is different. Anyway, that's how I feel with this.

I have the 1.5 JDK, and just installed tomcat 5.5, and all my classes seem to compile except for servlets.

The code that I am trying to compile is this.

package com.wittycritics.web;

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

public class BeerSelect extends HttpServlet {

public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {

response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("Beer Selection Advice<br>");
String c = request.getParameter("color");
out.println("<br>Got beer color " + c);

} // end of method

} // end of class

and I'm trying to compile it by typing this at the prompt

javac -classpath /Apache/Tomcat5.5/common/lib/servlet-api.jar:classes:. -d ../classes com/wittycritics/web/BeerSelect.java

However, when I hit enter, it can't find any of the javax imports.

Does anyone have any idea why this is happening? I don't believe I am typing anything wrong, should I change my classpath to something outside of the 1.5 jdk?

Thanks in advance for your help


Teaching yourself anything is always the cheapest way, but it definitely takes a lot of time and effort.<br /> <br />Thank you javaranch <a href="http://"http://faq.javaranch.com/view?HowToAskQuestionsOnJavaRanch"" target="_blank" rel="nofollow">Learn How to Ask Your Question</a> and be nice
Nicholas Carrier
Ranch Hand

Joined: Apr 14, 2005
Posts: 78
It looks like this ranch room had the solution, possibly, but when I click on the link inside the room, the page could not be found.

Slowly looking to find my answer, maybe someday I will compile a servlet.

Thanks again for any help anyone could give.
Tim Baker
Ranch Hand

Joined: Oct 04, 2003
Posts: 541
The link that didn't work is now:

http://www.coderanch.com/t/347562/Servlets/java/Tomcat-Instructions-explained

Didn't take a genious to transform the old style into the new one

Hope this helps


Kim Jong II (North Korea's Dear Leader) said:Nuclear weapons don't kill people, people kill people.
Nicholas Carrier
Ranch Hand

Joined: Apr 14, 2005
Posts: 78
I wanted to say thanks you for making that link visible, but unfortunately it didn't help me at all. I can start up tomcat, and run the home page without a problem(I have version 5.5 with appache). When I start it up, and then go to localhost:8080 the homepage loads. The problem is that I can't compile servlets, so therefore I can't create my own webapps.

Any have any ideas?

Down the yellow brick road I continue, hoping one day to find Oz.
Nicholas Carrier
Ranch Hand

Joined: Apr 14, 2005
Posts: 78
Wow, this might be the longest I've ever gone without an answer. I almost feel like I've asked a decent question, even though I know it's such a beginer question. Anyways, I'm also running windows XP.
Nicholas Carrier
Ranch Hand

Joined: Apr 14, 2005
Posts: 78
In my path file I have the servlet-api.jar file that came with tomcat, am I supposed to have another file in my path?

I noticed that other people have a servlet.jar file in their path, but there is no servlet.jar file on my computer. It must not have come with Tomcat 5.5.
[ June 24, 2005: Message edited by: Nicholas Carrier ]
Nicholas Carrier
Ranch Hand

Joined: Apr 14, 2005
Posts: 78
That's my guess as to why this isn't working, is the servlet.jar file hidden somewhere inside another JAR file in Tomcat 5.5.9?
Nicholas Carrier
Ranch Hand

Joined: Apr 14, 2005
Posts: 78
Ok, so I'm pretty sure this is the problem, and I listed the table of the servlet-api.jar file, and I think this all the classes that are required in there, so MAYBE (and this is most likely not a maybe, but the actual cause) I have the servlet-api.jar file type incorrectly in the path. Here is how I have it listed E:\Tomcat 5.5\common\lib;

Any ideas?

Thanks again.
[ June 24, 2005: Message edited by: Nicholas Carrier ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61434
    
  67

E:\Tomcat 5.5\common\lib


E:\Tomcat 5.5\common\lib\servlet-api.jar

When it comes to jar files, you need to put the jar file in the path, not just its containing folder.

Also, servlet.jar is the pre-Tomcat 5 jar file. As of Tomcat 5 it's servlet-api.jar. If you reference any of the JSP API's you will also need jsp-api.jar.
[ June 24, 2005: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Nicholas Carrier
Ranch Hand

Joined: Apr 14, 2005
Posts: 78
I tried adding that servlet-api.jar into my path and it still wouldn't compile. I'll try adding all the JAR's and let you know. I have still yet to try and create a JSP file because it would be kind of pointless without a servlet

Still trying.

Also, if anyone thinks they can help me via phone, just pm me and I'll give you my number to call.

Thanks again for reading.
[ June 24, 2005: Message edited by: Nicholas Carrier ]
Nicholas Carrier
Ranch Hand

Joined: Apr 14, 2005
Posts: 78
I feel like I'm missing something really easy, but what ever it is, it's shooting over my head, over and over again.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61434
    
  67

It's clearly a classpath issue at this point. How are you setting up the classpath? What is its exact setting? And what does your compile command look like?

Also post the exact text of the compilation errors.
Nicholas Carrier
Ranch Hand

Joined: Apr 14, 2005
Posts: 78
That's what I was thinking but I couldn't figure it out.

Here is my exact path (note it's in environment variables for win XP).

%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;E:\java\bin;E:\Tomcat 5.5\bin\bootstrap.jar;C:\Program Files\ATI Technologies\ATI Control Panel;E:\Tomcat\common\lib\servlet-api.jar;

The exact error message I am getting is:

BeerSelect.java:3: package javax.servlet.* does not exist
import javax.servlet.http.*;
^

BeerSelect.java:4: package javax.servlet.http does not exist
import javax.servlet.http.*;
^

BeerSelect.java:7: cannot find symbol
symbol: class HttpServlet
public class BeerSelect extends HttpSevlet {
^

BeerSelect.java:9: cannot find symbol
symbol : class HttpServletRequest
location: class com.wittycritics.web.BeerSelect
public void doPost(HttpServletRequest request,
^

BeerSelect.java:10: cannot find symbol
symbol : class HttpServletRequest
location: class com.wittycritics.web.BeerSelect
public void doPost(HttpServletRequest response,
^

BeerSelect.java:11: cannot find symbol
symbol : class ServletException
location: class com.wittycritics.web.BeerSelect
throws IOException, ServletException {
^
6 errors


I've tried compiling the file from it's directory using javac BeerSelect.java

I've tried compiling the file using the javac -d classes src\com\wittycritics\web\BeerSelect.java

and got the same problem

I've also tried using the class path in the command

javac -classpath E:\Tomcat\common\lib\servlet-api.jar:classes:. -d classes src/com/wittycritics/web/BeerSelect.

Along with javac -classpath /Tomcat/common/lib/servlet-api.jar:classes:. -d classes src/com/wittycritics/web/BeerSelect.

All of which give me the same answer.

[ June 24, 2005: Message edited by: Nicholas Carrier ]
[ June 24, 2005: Message edited by: Nicholas Carrier ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61434
    
  67

Here is my exact path (note it's in environment variables for win XP).


What environment variable are you showing? That looks suspiciously like PATH, which is not in the least the same as CLASSPATH.

If you've been adding your classpath entries to PATH, remove them and make sure PATH is the way it was befor tinkering. Then create an environment variable named CLASSPATH with the classpath entries.

Oh, and sooner or later, preferably sooner, adopt Ant for your builds. You'll thank me for it.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61434
    
  67

And, I think your command line-supplied classpath didn't work because you used the colon character as your classpath separator. Under Windoze, which always insists on doing its own thing, the classpath separator is semi-colon.
Nicholas Carrier
Ranch Hand

Joined: Apr 14, 2005
Posts: 78
I hope you don't take this the wrong way, but I love you. Thank you very much. It was because I was putting the variable in PATH instead of CLASSPATH. Creating CLASSPATH fixed the problem after I restarted my computer. Thank you very much. I now can complete my dream of becoming part of the servlet/JSP world.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61434
    
  67

I hope you don't take this the wrong way


Taken in the spirit in which it was meant. Glad to help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet compiler error