报错提示:HTTP method GET is not supported by this URL
jsp代码:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
用户名:
密 码:
servlet代码:
package mysqlConnect;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;
public class loginServlet extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Constructor of the object.
*/
/**
* Destruction of the servlet. <br>
*/
@Override
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
*/
/**
* 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
*/
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
@SuppressWarnings("unused")
String resMsg;
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String username = request.getParameter("username"); // 从 request 中获取名为 username 的参数的值
@SuppressWarnings("unused")
String password = request.getParameter("password"); // 从 request 中获取名为 password 的参数的值
try {
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//连接到数据库bookstore
Connection connection =(Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/bookstore acterEncoding=utf-8");
//通过连接创建statement
Statement statement =(Statement) connection.createStatement();
ResultSet rs=statement.executeQuery("select * from userlist where =用户名'"+username+"'");
if(!("username").equals(rs)){ // 如果用户名不存在
resMsg = "该用户名不存在,请检查后重新登录或注册新用户";
out.println("<a href='login.jsp' style='font-size:30px;color:red'>返回登录</a>");
} else{
response.sendRedirect("bookshow.jsp");
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
// add this section
}
out.println("");
out.flush();
out.close();
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
@Override
public void init() throws ServletException {
// Put your code here
}
}