当前位置: 代码迷 >> J2EE >> 一个简单servlet+jsp+javabean报错 405 HTTP method POST is not supported by this URL解决办法
  详细解决方案

一个简单servlet+jsp+javabean报错 405 HTTP method POST is not supported by this URL解决办法

热度:255   发布时间:2016-04-22 01:51:21.0
一个简单servlet+jsp+javabean报错 405 HTTP method POST is not supported by this URL
本人菜鸟,求高手帮帮忙。要做毕业设计了。。。。。

CheckAdmin:
package com.tyhg.action;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class CheckAdmin extends HttpServlet{

protected void processRequest(HttpServletRequest request,HttpServletResponse response) throws IOException,ServletException{
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String name = request.getParameter("username");
String pass = request.getParameter("password");
if(name.equalsIgnoreCase("admin") && pass.equals("12345")){
response.sendRedirect("http://www.baidu.com");
}
else{
response.sendRedirect("http://www.baidu.com");
}
out.close();
}

protected void doPost(HttpServletResponse response,HttpServletRequest request) throws IOException,ServletException{
processRequest(request,response);
}
protected void doGet(HttpServletResponse response,HttpServletRequest request) throws IOException,ServletException{
doPost(request,response);
}
}

web.xml:
 <servlet> 
  <servlet-name>CheckAdmin</servlet-name>
  <servlet-class>com.tyhg.action.CheckAdmin</servlet-class>
  </servlet>
  <servlet-mapping>
  <servlet-name>CheckAdmin</servlet-name>
  <url-pattern>/CheckAdmin</url-pattern>
  </servlet-mapping>
jsp:
<form action="CheckAdmin" method="post" id="login" name="login" onsubmit="JavaScript: return check_Null();">

------解决方案--------------------
check_Null这里面写的什么啊,
还有你指示迁移画面而已,用get方式就可以了吧。
------解决方案--------------------
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String name = request.getParameter("username");
String pass = request.getParameter("password");
if(name.equalsIgnoreCase("admin") && pass.equals("12345")){
response.sendRedirect("http://www.baidu.com");
}
else{
response.sendRedirect("http://www.baidu.com");
}
out.close();
把你的这段代码写在dopost方法里面
------解决方案--------------------
报的错,应该是没找到url
  相关解决方案