HTTP method POST is not supported by this URL
我做了一个登录页面 用servlet来处理密码验证 servlet是要连接数据库的 但是
页面一提交之后就
报错HTTP method POST is not supported by this URL
package my;
import
java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import
java.sql.SQLException;
import java.sql.Statement;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import
javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class Loginservlet extends HttpServlet {
Connection conn;
Statement stmt;
PreparedStatement pstmt;
ResultSet rst;
/**
* 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 {
doPost(request,response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response, ServletRequest session)
throws ServletException, IOException {
ServletContext application=getServletContext() ;
ServletConfig config=getServletConfig() ;
response.setContentType("text/html;charset=utf-8");
PrintWriter out=response.getWriter();
// HttpSession session =request.getSession();
request.setCharacterEncoding("utf-8");
System.out.println("hello6");
String userid = request.getParameter("userid");
String password = request.getParameter("password");
System.out.println("hello7");
try
{ System.out.println("hello7");
rst = stmt.executeQuery("select * from userinfo where userid='"+userid+"'");
if(rst.next())
{
if(rst.getString("password").equals(password))
{
response.sendRedirect("./index.jsp");
System.out.println("密码正确");
session.setAttribute("user",userid);
}
else
response.sendRedirect("login.jsp?info=1");
System.out.println("密码正确");
}
else
{
response.sendRedirect("login.jsp?info=1");
System.out.println("密码正确");
}
}
catch(Exception e)
{
e.printStackTrace();
}