首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

,新手上路希望大家帮忙!

2011-12-05 
紧急求助,新手上路希望大家帮忙!!!程序的源代码如下:packagemypackimportjavax.servlet.*importjavax.se

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

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{
                                                                          ^
D:\javawork\12.java:8:   cannot   find   symbol
symbol     :   class   ServletConfig


location:   class   mypack.DispatchServlet
      public   void   init(ServletConfig   config)
                                        ^
D:\javawork\12.java:9:   cannot   find   symbol
symbol     :   class   ServletException
location:   class   mypack.DispatchServlet
            throws   ServletException{
                          ^
D:\javawork\12.java:12:   cannot   find   symbol
symbol     :   class   HttpServletRequest
location:   class   mypack.DispatchServlet
      public   void   doGet(HttpServletRequest   request,
                                          ^
D:\javawork\12.java:13:   cannot   find   symbol
symbol     :   class   HttpServletResponse
location:   class   mypack.DispatchServlet
              HttpServletResponse   response)
              ^
D:\javawork\12.java:14:   cannot   find   symbol
symbol     :   class   ServletException
location:   class   mypack.DispatchServlet
        throws   ServletException,IOException{
                      ^
D:\javawork\12.java:18:   cannot   find   symbol
symbol     :   class   HttpServletRequest
location:   class   mypack.DispatchServlet
      public   void   doPost(HttpServletRequest   request,
                                            ^
D:\javawork\12.java:19:   cannot   find   symbol
symbol     :   class   HttpServletResponse
location:   class   mypack.DispatchServlet
              HttpServletResponse   response)
              ^
D:\javawork\12.java:20:   cannot   find   symbol
symbol     :   class   ServletException
location:   class   mypack.DispatchServlet
              throws   ServletException,IOException{
                            ^
D:\javawork\12.java:10:   cannot   find   symbol
symbol     :   variable   super
location:   class   mypack.DispatchServlet
            super.init(config);
            ^
D:\javawork\12.java:29:   cannot   find   symbol
symbol     :   class   ServletContext
location:   class   mypack.DispatchServlet
      ServletContext   context=getServletContext();
      ^
D:\javawork\12.java:29:   cannot   find   symbol
symbol     :   method   getServletContext()
location:   class   mypack.DispatchServlet
      ServletContext   context=getServletContext();


                                                    ^
D:\javawork\12.java:31:   cannot   find   symbol
symbol     :   class   RequestDispatcher
location:   class   mypack.DispatchServlet
      RequestDispatcher   dispatcher=
      ^
16   errors




[解决办法]
1.文件名命名错误,应该命名为:DispatchServlet.java
2.classpath中的包不够,增加j2ee.jar或(servlet.jar和jsp.jar)。
[解决办法]
从头好好细学一下吧,这些问题都是学JAVA时一开始就强调的事情。
[解决办法]
标准答案=====inkfish(邬贼) ( ) 信誉:100

搂主要虚心学习哦...

热点排行
Bad Request.