-
Servlet验证出现405错误,HTTP method POST is not supported by this URL10
我找了很久确实没有找出错误!!看看错在哪儿行吗?
谢谢!!
我用Form表单提交:<form action="user_dao_servlet" method="post"> 用户名: <input type="text" name="userName"/><br> 密码: <input type="password" name="userPassword"/><br> 确认密码: <input type="password" name="confirmPassword"/><br> 邮箱: <input type="text" name="userEmail"/><br> 安全问题: <input type="text" name="userQuestion"/><br> 答案: <input type="text" name="userAnswer"/><br> <input type="submit" value="提交"/> <input type="reset" value="重置"/> </form>
以下是我的Servlet代码: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); } } }
以下是在WEB.XML里面的配置:<servlet> <servlet-name>userDAO</servlet-name> <servlet-class>org.mm.servlet.UserDAOServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>userDAO</servlet-name> <url-pattern>/user_dao_servlet</url-pattern> </servlet-mapping>
2012年9月19日 22:07
2个答案 按时间排序 按投票排序
-
采纳的答案
我看到了
public class UserDAOServlet extends HttpServlet {
public class UserLoginServlet extends HttpServlet {
什么意思。。
按照你的web.xml中的
<servlet-class>org.mm.servlet.UserDAOServlet</servlet-class>
可是你写了2个
public class UserDAOServlet extends HttpServlet {
public class UserLoginServlet extends HttpServlet {
都继承了 HttpServlet 导致系统找不到他要用的doPost()方法
正确应该是
public class UserDAOServlet extends HttpServlet {
把public class UserLoginServlet extends HttpServlet { 删了。
2012年9月19日 22:49
-
String page = "/user_register.jsp";
request.getRequestDispatcher(page).forward(request, response);2012年9月19日 22:36
相关推荐
当您遇到"405 - HTTP method GET is not supported by this URL"这样的问题时,通常意味着您的服务器端代码没有正确处理GET请求,或者请求被误定向到了一个不期望GET方法的Servlet。 首先,我们需要理解HTTP协议中...
本文将深入探讨HTTP Servlet请求的源码实现,并针对"HTTP method GET is not supported by this URL"这一常见错误进行分析和解决。 首先,让我们理解HTTP Servlet的工作原理。每当一个HTTP请求到达Web服务器时,...
Called by the server (via the service method) to allow a servlet to handle a POST request. doPut(HttpServletRequest, HttpServletResponse) - Method in class javax.servlet.http.HttpServlet Called by ...
然而,一个映射可能是由一个URL和许多Servlet实例组成,例如:一个分布式的Servlet引擎可能运行在不止一个的服务器中,这样的话,每一个服务器中都可能有一个Servlet实例,以平衡进程的载入。作为一个Servlet的...
In this program we are going to know how the server determines whether the password entered by the user is correct or not. This whole process is controlled on the server side. Multiple forms in jsp ...
4. **服务器端处理**:为了实现图片上传和文件管理,需要在服务器端(例如使用Servlet或Spring MVC)编写相应的处理逻辑,接收并处理上传的文件,返回成功或失败信息。 在实际使用中,可能会遇到以下问题: - **...
例如,如果请求使用的是`GET`方法但子类未实现`doGet`方法,那么会返回405 Method Not Allowed或者400 Bad Request的错误码。 ##### 4. 示例:doGet方法 下面是一个简化版的`doGet`方法实现示例: ```java ...
405(Method Not Allowed)表示请求方法(如GET、POST)不被允许。406(Not Acceptable)说明服务器无法提供满足请求的资源格式。408(Request Timeout)表示服务器等待请求超时。409(Conflict)表示请求与当前资源...
* Servlet adapter provided to let you deploy any Restlet application in Servlet compliant containers like Tomcat, when the usage of standalone HTTP connectors is not possible. * Implementation of ...
the ability to see how many new mail messages they have, are not supported by POP at all. These capabilities are built into programs like Eudora or Microsoft Outlook, which remember things like the ...