<display-name></display-name>
  <servlet>
    <description>This is the description of my J2EE component</description>
    <display-name>This is the display name of my J2EE component</display-name>
    <servlet-name>login</servlet-name>
    <servlet-class>view.LoginServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>login</servlet-name>
    <url-pattern>/LoginServlet</url-pattern>
  </servlet-mapping>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>
login.jsp内 form<form action="/com.AnswerSystem/view/LoginServlet" method="post" onSubmit="validate(this)">
不知道哪有错  求大神指出啊!!

解决方案 »

  1.   


    这是 servlet
    package view;import java.io.IOException;
    import java.util.ArrayList;
    import java.util.List;
    import model.*;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;import control.DAOfactory;import model.Student;public class LoginServlet extends HttpServlet { /**
     * Constructor of the object.
     */
    public LoginServlet() {
    super();
    } /**
     * Destruction of the servlet. <br>
     */
    public void destroy() {
    super.destroy(); // Just puts "destroy" string in log
    // Put your code here
    } /**
     * The doGet method of the servlet. <br>
     *
     * This method is called when a form has its tag value method equals to get.
     * 
     * @param request the request send by the client to the server
     * @param response the response send by the server to the client
     * @throws ServletException if an error occurred
     * @throws IOException if an error occurred
     */
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    String userid = request.getParameter("userid");
    String password = request.getParameter("password");
    String user = request.getParameter("user");
    List<String> info = new ArrayList<String>();
    if(userid == null || "".equals(userid)){
    info.add("用户名不能为空");
    }
    if(password == null || "".equals(password)){
    info.add("密码不能为空");
    }
    if(info.size() == 0){
    if(user.equals("student")){
    Student student = new Student();
    student.setS_ID(userid);
    student.setPassword(password);
    try{
    if(DAOfactory.getUserDAOInstance().findLogin(student)){
    info.add("欢迎学生"+student.getS_Name()+"光临");
    request.setAttribute("info", info);
    request.getRequestDispatcher("studentIndex.jsp").forward(request, response);

    }else{
    info.add("用户登录失败");
    request.getRequestDispatcher("login.jsp").forward(request, response);
    }
    }catch(Exception e){e.printStackTrace();}
    }

    if(user.equals("teacher")){
    Teacher teacher = new Teacher();
    teacher.setT_ID(userid);
    teacher.setPassword(password);
    try{
    if(DAOfactory.getUserDAOInstance().findLogin(teacher)){
    info.add("欢迎老师"+teacher.getT_Name()+"光临");
    request.setAttribute("info", info);
    request.getRequestDispatcher("teacherIndex.jsp").forward(request, response);
    }else{
    info.add("用户登录失败");
    request.getRequestDispatcher("login.jsp").forward(request, response);
    }
    }catch(Exception e){e.printStackTrace();}
    }
    if(user.equals("admin")){
    Admin admin = new Admin();
    admin.setA_ID(userid);
    admin.setPassword(password);
    try{
    if(DAOfactory.getUserDAOInstance().findLogin(admin)){
    info.add("欢迎管理员"+admin.getA_Name()+"光临");
    request.setAttribute("info", info);
    request.getRequestDispatcher("adminIndex.jsp").forward(request, response);
    }else{
    info.add("用户登录失败");
    request.getRequestDispatcher("login.jsp").forward(request, response);
    }
    }catch(Exception e){e.printStackTrace();}
    }

    }
    info.add("用户登录失败");
    request.setAttribute("info", info);
    request.getRequestDispatcher("login.jsp").forward(request, response);


    } /**
     * The doPost method of the servlet. <br>
     *
     * This method is called when a form has its tag value method equals to post.
     * 
     * @param request the request send by the client to the server
     * @param response the response send by the server to the client
     * @throws ServletException if an error occurred
     * @throws IOException if an error occurred
     */
    public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException { this.doGet(request, response);
    } /**
     * Initialization of the servlet. <br>
     *
     * @throws ServletException if an error occurs
     */
    public void init() throws ServletException {
    // Put your code here
    }}
      

  2.   

     <url-pattern>/LoginServlet</url-pattern>
    这是URL
    form里应该这样  :     action = "LoginServlet"
      

  3.   

    从你form中的action看
    <servlet-class>view.LoginServlet</servlet-class>应配置完整路径:包名.LoginServlet另将action改为与<url-pattern>/LoginServlet</url-pattern>一致
      

  4.   

    web.xml
     <servlet-class>com.AnswerSystem.view.LoginServlet</servlet-class>login.jsp
    <form action="<%=request.getContextPath()%>/LoginServlet" method="post" onSubmit="validate(this)">
      

  5.   

    这个好像应该放在web.xml里的吧
      

  6.   

    url应该是错了,应该没有工程名
      

  7.   

    <form action="/com.AnswerSystem/view/LoginServlet" method="post" onSubmit="validate(this)">
    上面的标记颜色的部分给去掉试试
    你这个请求路径不对
    怎么还有一个view/
      

  8.   

    路径在web.xml里面配置,而不是写全路径
      

  9.   

    action后面添加的不是完整路径吧