little__Fiona 2017-06-10 03:01 采纳率: 0%
浏览 860

servlet报错 一个用户登录页面

报错提示: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
}

}

  • 写回答

5条回答

  • 枯木_叶 2017-06-10 03:18
    关注

    loginServlet缺少doGet方法

    评论

报告相同问题?

悬赏问题

  • ¥15 Matlab问题解答有两个问题
  • ¥50 Oracle Kubernetes服务器集群主节点无法访问,工作节点可以访问
  • ¥15 LCD12864中文显示
  • ¥15 在使用CH341SER.EXE时不小心把所有驱动文件删除了怎么解决
  • ¥15 gsoap生成onvif框架
  • ¥15 有关sql server business intellige安装,包括SSDT、SSMS。
  • ¥15 stm32的can接口不能收发数据
  • ¥15 目标检测算法移植到arm开发板
  • ¥15 利用JD51设计温度报警系统
  • ¥15 快手联盟怎么快速的跑出建立模型