Servlet验证出现405错误,HTTP method POST is not supported by this URL

我找了很久确实没有找出错误!!看看错在哪儿行吗?
谢谢!!
我用Form表单提交:
[code="html"]


用户名:

密码:

确认密码:

邮箱:

安全问题:

答案:



[/code]
以下是我的Servlet代码:
[code="java"]public class UserDAOServlet extends HttpServlet {
public class UserLoginServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}

public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");        //统一设置编码
        String page = "user_register.jsp";
        String code = request.getParameter("code");
        List<String> errors = new ArrayList<String>();
        // 验证码验证
        if (code == null || "".equals(code)) {      
            errors.add("验证码为空!");
        } else {
            String rand = (String) request.getSession().getAttribute("rand"); 
            if (!code.equalsIgnoreCase(rand)) {
                errors.add("验证码错误!!") ;
            }
        }
        //取出接受参数进行验证
        String userName = request.getParameter("userName");
        String userPassword = request.getParameter("userPassword");
        String confirmPassword = request.getParameter("confirmPassword");
        String userEmail = request.getParameter("userEmail");
        String userQuestion = request.getParameter("userQuestion");     
        String userAnswer = request.getParameter("userAnswer");     
        String userRealName = request.getParameter("userRealName");
        String tele = request.getParameter("tele");
        String address = request.getParameter("address");
        String sex = request.getParameter("sex");

        if(!(userPassword.equals(confirmPassword))){
            errors.add("两次输入密码不一样!");
        }
        if (userName == null || "".equals(userName)) {
            errors.add("用户名不能为空!");
        }
        if (userPassword == null || "".equals(userPassword)) {
            errors.add("密码不能为空!");
        }
        if(errors.size()==0){            // 现在没有任何的错误信息
            User vo=new User();
            vo.setUserName(userName);
            vo.setUserPassword(new MD5Code().getMD5ofStr(userPassword)) ;
            vo.setAddress(address);
            vo.setSex(sex);
            vo.setTele(tele);
            vo.setUserQuestion(userQuestion);
            vo.setUserAnswer(userAnswer);
            vo.setUserEmail(userEmail);
            vo.setUserRealName(userRealName);
            try {
                if(DAOFactory.getIUserDAOInstance().doCreate(vo)){
                    request.getSession().setAttribute("user", vo) ;        // 现在保存对象
                    request.setAttribute("userName", userName);
                    page = "register_success.jsp" ;
                } else {
                    errors.add("用户名或密码错误!");
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        request.setAttribute("errors", errors) ;
        request.getRequestDispatcher(page).forward(request, response);
        }

}
}[/code]

以下是在WEB.XML里面的配置:
[code="xml"]
userDAO
org.mm.servlet.UserDAOServlet


userDAO
/user_dao_servlet

[/code]

2个回答

我看到了
public class UserDAOServlet extends HttpServlet {

public class UserLoginServlet extends HttpServlet {
什么意思。。
按照你的web.xml中的
org.mm.servlet.UserDAOServlet

可是你写了2个
public class UserDAOServlet extends HttpServlet {

public class UserLoginServlet extends HttpServlet {
都继承了 HttpServlet 导致系统找不到他要用的doPost()方法
正确应该是
public class UserDAOServlet extends HttpServlet {

把public class UserLoginServlet extends HttpServlet { 删了。

Shall_we_talk
Shall_we_talk 5555,居然出这样问题!!我是复制另外一个Servlet的。。。。
大约 8 年之前 回复

String page = "/user_register.jsp";

request.getRequestDispatcher(page).forward(request, response);

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐