package mypack;import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;public class DispatherServlet 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{
  
  doPost(request,response);
}

public void doPost(HttpServletRequest request,HttpServletResponse response)
  throws ServletException,IOException{
  
  String usename=request.getParameter("usename");
  
  String password=request.getParameter("password");
  
  request.setAttribute("USER",username);
  
  request.setAttribute("PASSWORD",password);
  
  ServletContext context=getServletContext();
  
  System.out.println("Redirecting to "+target);
  RequestDispatcher dispatcher=context.getRequestDispatcher(target);
  dispatcher.forward(request,response);
}

public void destroy(){
  }
}
DispatherServlet.java:17: 找不到符号
符号: 类 IOException
位置: 类 javax.servlet.ServletException
  throws ServletException.IOException{
                         ^
DispatherServlet.java:29: 找不到符号
符号: 变量 username
位置: 类 mypack.DispatherServlet
  request.setAttribute("USER",username);
                              ^
2 错误问题比较基础,希望各位帮帮忙,谢谢!

解决方案 »

  1.   

    String usename=request.getParameter("usename"); 
      request.setAttribute("USER",username)
    一个usename 一个username   当然不对
    两个一至就行了
      

  2.   

    找不到符号,你这应该是在jsp中提交表单由servlet接收吧
    应该是jsp表单中没有<input name="username" >吧
      

  3.   

    request.setAttribute("USER",username); 
    这个不会报错吗?
    username没有定义啊
      

  4.   

     这有错误看
      String usename=request.getParameter("usename"); 
               ^                              ^  String password=request.getParameter("password"); 
      
      request.setAttribute("USER",username); 
                                    ^
      

  5.   

    这有错误看 
      String usename=request.getParameter("usename"); 
     String password=request.getParameter("password"); 
      
      request.setAttribute("USER",username); 
                                    
      

  6.   

    这错误要是在Eclipse可是会出红线的?难倒楼主没看见。
      

  7.   

    以按照各位的说法修改了,也可以编译了,但是运行时会报错,提示找不到:
    type Status reportmessage /helloapp/dispatcherdescription The requested resource (/helloapp/dispatcher) is not available.文件
    \helloapp
    |--index.htm
    |--login.jsp
    |--hello.jsp
    |--WEB-INF
       |--classes
          |--mypack
             |--DispatcherServlet.java
             |--DispatcherServlet.class
       |--lib
       |--web.xml
       
    -------------------------------------
       
    index.htm   <html>
    <head>
    <title>helloapp</title>
      <body>
        <p><font size="7">Welcome ha</font></p>
        <p><a href="login.jsp?language=English">English Version</a></p>
      </body>
    </html>--------------------------------------login.jsp<html>
    <head>
       <title>hello</title>
    </head>
    <body>
      <br>
      <form name="loginForm" method="post" action="dispatcher">
       <table>
       <tr>
       <td><div align="right">User Name</div></td>
       <td><input type="text" name="username"></td>
       </tr>
      
       <tr>
       <td><div align="right">Password</div></td>
       <td><input type="password" name="password"></td>
       </tr>
      
       <tr>
       <td></td>
       <td><input type="Submit" name="Submit" value="Submit"></td>
       </tr>
       </table>
      </form>
    </body>
    </html>
    -------------------------------------DispatcherServlet.javapackage mypack;import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.util.*;public class DispatcherServlet 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{
      
      doPost(request,response);
    }

    public void doPost(HttpServletRequest request,HttpServletResponse response)
      throws ServletException,IOException{
      
      String username=request.getParameter("username");
      
      String password=request.getParameter("password");
      
      request.setAttribute("USER",username);
      
      request.setAttribute("PASSWORD",password);
      
      ServletContext context=getServletContext();
      
      System.out.println("Redirecting to "+target);
      RequestDispatcher dispatcher=context.getRequestDispatcher(target);
      dispatcher.forward(request,response);
    }

    public void destroy(){
      }
    }
    -------------------------------------------
    web.xml<input type="image" src="<?xml version="1.0" encoding="ISO-8859-1"?>
    <!--
     Licensed to the Apache Software Foundation (ASF) under one or more
      contributor license agreements.  See the NOTICE file distributed with
      this work for additional information regarding copyright ownership.
      The ASF licenses this file to You under the Apache License, Version 2.0
      (the "License"); you may not use this file except in compliance with
      the License.  You may obtain a copy of the License at      http://www.apache.org/licenses/LICENSE-2.0  Unless required by applicable law or agreed to in writing, software
      distributed under the License is distributed on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      See the License for the specific language governing permissions and
      limitations under the License.
    --><web-app xmlns="http://java.sun.com/xml/ns/j2ee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
        version="2.4">  <display-name>Welcome to Tomcat</display-name>
      <description>
         Welcome to Tomcat
      </description><!-- JSPC servlet mappings start -->    <servlet>
            <servlet-name>org.apache.jsp.index_jsp</servlet-name>
            <servlet-class>org.apache.jsp.index_jsp</servlet-class>
        </servlet>
        <servlet-mapping>
            <servlet-name>org.apache.jsp.index_jsp</servlet-name>
            <url-pattern>/index.jsp</url-pattern>
        </servlet-mapping>
     </web-app>
     
     <web-app>   
        <servlet>
            <servlet-name>dispatcher</servlet-name>
            <servlet-class>mypack.DispatcherServlet</servlet-class>
        </servlet>
        
        <servlet-mapping>
            <servlet-name>dispatcher</servlet-name>
            <url-pattern>/dispatcher</url-pattern>
        </servlet-mapping><!-- JSPC servlet mappings end --></web-app>
    ">
    ------------------------------------------classpath
    .;C:\Program Files\Java\jdk1.6.0_03\lib\tools.jar;
    C:\Program Files\Java\jdk1.6.0_03\lib\dt.jar;
    C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\msbase.jar;
    C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\ROOT\com\microsoft\jdbc\sqlserver;
    C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\mssqlserver.jar;
    C:\Program Files\Java\jdk1.6.0_03\bin;
    C:\Program Files\Apache Software Foundation\Tomcat 5.5\common\lib\servlet-api.jar
    path
    C:\Program Files\StormII\Codec;
    C:\Program Files\StormII;
    %JAVA_HOME%\binJAVA_HOME
    C:\Program Files\Java\jdk1.6.0_03
    尝试了一天,还是没有结果
    希望各位帮帮忙!!