日期:2014-05-18  浏览次数:20640 次

紧急求助,新手上路希望大家帮忙!!!
程序的源代码如下:

package   mypack;
import   javax.servlet.*;
import   javax.servlet.http.*;
import   java.io.*;
import   java.util.*;
public   class   DispatchServlet   extends   HttpServlet{
      private   String   target= "/hello.jsp ";
      public   void   init(ServletConfig   config)
            throws   ServletException{
            super.init(config);
      }
      public   void   doGet(HttpServletRequest   request,
              HttpServletResponse   response)
        throws   ServletException,IOException{
      //If   it   is   a   get   request   forward   to   doPost()
      doPost(request,response);
      }
      public   void   doPost(HttpServletRequest   request,
              HttpServletResponse   response)
              throws   ServletException,IOException{
      //Get   the   username   from   the   request
      String   username=request.getParameter( "username ");
      //Get   the   password=request.getParamerer( "password ")
      String   password=request.getParameter( "password ");
      //Add   the   user   to   the   request
      request.setAttribute( "USER ",username);
      request.setAttribute( "PASSWORD ",password);
    //Forward   the   request   to   the   target   named
      ServletContext   context=getServletContext();
      System.out.println( "Redirecting   to   "+target);
      RequestDispatcher   dispatcher=
            context.getRequestDispatcher(target);
      dispatcher.forward(request,response);
    }  
  public   void   destroy(){
  }
}


错误的地方如下!
D:\javawork\12.java:6:   class   DispatchServlet   is   public,   should   be   declared   in   a   file   named   DispatchServlet.java
public   class   DispatchServlet   extends   HttpServlet{
              ^
D:\javawork\12.java:2:   package   javax.servlet   does   not   exist
import   javax.servlet.*;
^
D:\javawork\12.java:3:   package   javax.servlet.http   does   not   exist
import   javax.servlet.http.*;
^
D:\javawork\12.java:6:   cannot   find   symbol
symbol:   class   HttpServlet
public   class   DispatchServlet   extends   HttpServlet{
                                  &