(1)index.html
<html>
<head>
     <title>helloapp</title>
</head>
<body>
     <p><font size="7">Welcome to HelloApp</font></p>
     <p><a href="login.jsp" language=English">English version</a></p>
</body>
</html>(2)hello.jsp
<html>
<head>
     <title>helloapp</title>
</head>
<body>
     <b>Welcome:<%=request.getAttribute("USER")%></b>
</body>
</html>(3)login.jsp
<html>
<head>
     <title>helloapp</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>(4)DispatcherServlet.java
package 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(HttpServletRequestrequest,
            HttpServletResponse response)
   throws ServletException,IOException
{
doPost(request,response);
}
public void doPos(HttpServletRequestrequest,
           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);
RequestDispatcherdispatcher=
                       context.getRequestDispatcher(target);
dispatcher.forward(request,response);
}
public void destroy()
{
}
}目录为E:\Tomcat 5.5\webapps\helloapp
我把DispatcherServlet.java编译后的.class放到E:\Tomcat 5.5\webapps\helloapp\WEB-INI\classes\mypack下了可运行时有错
HTTP Status 404 - /helloapp/dispatcher--------------------------------------------------------------------------------type Status reportmessage /helloapp/dispatcherdescription The requested resource (/helloapp/dispatcher) is not available.各位大虾帮帮忙吧!
先在这谢谢各位了!!

解决方案 »

  1.   

    我在web.xml中加上了
             <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>
      

  2.   

    我司招聘程序开发工程师,一经录取待遇从优,具体情况请详见www.yuyao.com
      

  3.   

    action="mypack/DispatcherServlet"试试