1.i为java添加了路径C:\ Program Files(x86)\ Java \ jdk1.6.0_01 \ bin,为tomcat添加了C:\ TOMCAT \ apache-tomcat-7.0.55 \ lib。
2.i已在C:\ TOMCAT \ apache-tomcat-7.0.55 \ bin中启动startup.bat并且工作正常。
3.it显示在8084端口(localhost:8084 /)。
4.i在目录E中创建了一个MyServlet.java文件。
5.i想通过命令行(javac MyServlet.java)编译它,错误来了。
我已经尝试过并尝试过b:..(.. plz帮我修复它。
MyServlet.java代码:
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class MyServlet extends HttpServlet
{
public void doGet(HttpServletRequest request,HttpServletResposne response)
throws ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html><body>");
out.println("<h1>Hello Readers</h1>");
out.println("</body></html>");
}
}
和cmd错误:
E:\>javac MyServlet.java
MyServlet.java:1: package javax.servlet does not exist
import javax.servlet.*;
^
MyServlet.java:2: package javax.servlet.http does not exist
import javax.servlet.http.*;
^
MyServlet.java:7: package javax.servlet does not exist
import javax.servlet.ServletException;
^
MyServlet.java:8: package javax.servlet.http does not exist
import javax.servlet.http.HttpServlet;
^
MyServlet.java:9: package javax.servlet.http does not exist
import javax.servlet.http.HttpServletRequest;
^
MyServlet.java:10: package javax.servlet.http does not exist
import javax.servlet.http.HttpServletResponse;
^
MyServlet.java:12: cannot find symbol
symbol: class HttpServlet
public class MyServlet extends HttpServlet
^
MyServlet.java:14: cannot find symbol
symbol : class HttpServletRequest
location: class MyServlet
public void doGet(HttpServletRequest request,HttpServletResposne response)
^
MyServlet.java:14: cannot find symbol
symbol : class HttpServletResposne
location: class MyServlet
public void doGet(HttpServletRequest request,HttpServletResposne response)
^
MyServlet.java:15: cannot find symbol
symbol : class ServletException
location: class MyServlet
throws ServletException
^
10 errors
答案 0 :(得分:1)
答案 1 :(得分:1)
在定义类时忘记关键字class
,只需将class
放在类名