我的servlet是这样
package test;
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 test extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response)
  throws ServletException, IOException {
  PrintWriter out=response.getWriter();
  out.println("<html><body><h1>This is a servlet test.</h1></body></html>");
  out.flush();
  }
  }
可是,javac test.java时,告诉我有非法字符,这个是怎么回事?

解决方案 »

  1.   

    throws ServletException, IOException {
      PrintWriter out=response.getWriter();
      out.println("<html><body><h1>This is a servlet 这几行前面的空格都是汉字的空格
      

  2.   

    out.flush();
    这一行前面也是汉字空格
      

  3.   

    不知你是排版问题还是自己写错了。
    out.println("<html><body><h1>This is a servlet test.</h1></body></html>");
    改成out.println("<html><body><h1>This is a servlet test.</h1></body></html>");
      

  4.   

    多谢各位,是我多加了几个汉字的空格,可是,我现在把空格去掉了,还是出错了
    符号: 类 HttpServlet
    public class test extends HttpServlet {
                              ^
    test.java:10: 找不到符号
    符号: 类 HttpServletRequest
    位置: 类 test.test
    protected void doGet(HttpServletRequest request,HttpServletResponse response) th
    rows ServletException,IOException {
      

  5.   

    没找到HttpServlet,肯定是编译路径里没加lib文件
      

  6.   

    你的classpath加入了servlet-api.jar了吗?HttpServlet在这个包里面。
    这个包在tomcat的common\lib目录
      

  7.   

    我用的是zip版的Tomcat,是在startup。bat里设置的路径
    SET JAVA_HOME=C:\Program Files\Java\jdk1.5.0_04
    SET CATALINA_HOME=C:\tomcat5.5.15
    这么设完就没有再系统变量里设置,难道是错了么?
      

  8.   

    要再在classpath里加入这个jar包,是这样的么
      

  9.   

    呵呵,我现在不知道该用哪个工具好,所以就用了javac
      

  10.   

    各位再帮忙看看是什么原因好么,我已经在classpath里加入了servlet。jar了,可还是提示我没有找到Httpservlet