java servlet programming error [closed]
Want to improve this question? Add details and clarify the开发者_如何学Python problem by editing this post.
Closed 9 years ago.
Improve this questionC:\Tomcat5.5\webapps\WEB-INF\classes>javac MyServlet.java
MyServlet.java:2: package javax.servlet does not exist
import javax.servlet.*;
^
MyServlet.java:3: package javax.servlet.http does not exist
import javax.servlet.http.*;
^
MyServlet.java:5: cannot find symbol
symbol: class HttpServlet
public class MyServlet extends HttpServlet
^
MyServlet.java:7: cannot find symbol
symbol : class HttpServletRequest
location: class MyServlet
public void doGet(HttpServletRequest req, HttpServletResponse res) throws Serv
letException,IOException
^
MyServlet.java:7: cannot find symbol
symbol : class HttpServletResponse
location: class MyServlet
public void doGet(HttpServletRequest req, HttpServletResponse res) throws Serv
letException,IOException
^
MyServlet.java:7: cannot find symbol
symbol : class ServletException
location: class MyServlet
public void doGet(HttpServletRequest req, HttpServletResponse res) throws Serv
letException,IOException
^
6 errors
You're missing a servlet .jar
file to compile against.
To compile against it, use:
javac -cp servlet.jar {sources}
and investigate something like Ant for more complex builds. See this forum posting for a very similar issue and a fuller explanation of the issues.
Need to put the servlet.jar in your CLASSPATH when you compile.
The servlet.jar is part of Tomcat. You'll probably find it in servlet/lib on version 5.5.
You should know how to use -classpath option on javac.exe.
You'll probably find that there are other JARs missing as well. As you get compilation errors, keep finding the JARs that javac complains about and add them the same way to your CLASSPATH.
Or learn how to use Ant to build your app.
You are missing the servlet.jar file on your classpath
精彩评论