将值从jsp传递到servlet但servlet不可用

时间:2015-11-01 15:51:25

标签: java jsp servlets intellij-idea

我正在使用intellij idea 14使用servlet和jsp创建一个Web应用程序但是每当我尝试从jsp传递值时都会出现错误

HTTP Status 404 - /Books/BookSaleAuctionServlet

type Status report

message /Books/BookSaleAuctionServlet

description The requested resource is not available.

Apache Tomcat/7.0.30

Myfiles是: index.jsp

<form method= "get" action="Books/BookSaleAuctionServlet">
  UserName : <input type="text" name="name" id="name">
  Address : <input type="text" name="address" id="address">
  Contact : <input type="tel" name="contactNo" id="contactNo">
  Email : <input type="email" name="email" id="email">
    Password : <input type="password" name="pass" id="pass">
    <input type="submit" name="save">

并且BookSaleAuctionServlet包内有Books的servlet,它包含

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String name = request.getParameter("name");
        String address = request.getParameter("address");
        String contact = request.getParameter("contact");
        String email = request.getParameter("email");
        String pass = request.getParameter("pass");
        System.out.println("check 1");
        try {
            Class.forName("com.mysql.jdbc.Driver");
        }
        catch(ClassNotFoundException e) {
            System.out.println("Class not found "+ e);
        }
        System.out.println("JDBC Class found");
        try {
            Connection con = DriverManager.getConnection("jdbc:mysql://localhost/logins", "root", "");
            Statement stmt = con.createStatement();
            ResultSet rs = stmt.executeQuery
                    ("CREATE TABLE members (user_id int(11) NOT NULL AUTO_INCREMENT,\n" +
                            "    username varchar(45) NOT NULL,\n" +
                            "    password varchar(45) NOT NULL,\n" +
                            "    contact varchar(45) NOT NULL,\n" +
                            "    email varchar(45) NOT NULL,\n" +
                            "    PRIMARY KEY (user_id)\n" +
                            "); ");        }
        catch(SQLException e){
            System.out.println("SQL exception occured" + e);
        }
        System.out.print("done with databases");
    }

web.xml

<servlet>
        <servlet-name>BookSaleAuctionServlet</servlet-name>
        <servlet-class>Books.BookSaleAuctionServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>BookSaleAuctionServlet</servlet-name>
        <url-pattern>/bookSaleAuction</url-pattern>
    </servlet-mapping>

请帮助

1 个答案:

答案 0 :(得分:3)

变化 class refcounted { private: int count; public: refcounted() : count(0) { } int incRefCnt() { return ++count; } int decRefCnt() { return --count; } }; action="Books/BookSaleAuctionServlet"