从html表单获取类时调用servlet时出错

时间:2018-09-27 12:36:13

标签: java html hibernate servlets

我想将用户数据保存到动态Web应用程序中的数据库中,我使用hibernate保存到db中,我的注册页面(signup.html)包含许多字段,并且格式为action =“ rs” RegisterServlete,但我不知道为什么我会收到此错误

HTML: signup.html

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
    <h1 align="center">REGISTER</h1>

    <form action="rs" method="post">
        <table>

            <!----- First Name ---------------------------------------------------------->
            <tr>
                <td>FIRST NAME</td>
                <td><input type="text" name="First_Name" maxlength="30" /> (max
                    30 characters a-z and A-Z)</td>
            </tr>

            <!----- Last Name ---------------------------------------------------------->
            <tr>
                <td>LAST NAME</td>
                <td><input type="text" name="Last_Name" maxlength="30" /> (max
                    30 characters a-z and A-Z)</td>
            </tr>

            <!----- Date Of Birth -------------------------------------------------------->
            <tr>
                <td>AGE</td>
                <td><input type="number" name="age" maxlength="10" /></td>
            </tr>

            <!----- Email Id ---------------------------------------------------------->
            <tr>
                <td>EMAIL ID</td>
                <td><input type="text" name="Email_Id" maxlength="100" /></td>
            </tr>

            <!----- Mobile Number ---------------------------------------------------------->
            <tr>
                <td>MOBILE NUMBER</td>
                <td><input type="text" name="Mobile_Number" maxlength="10" />
                    (10 digit number)</td>
            </tr>

            <!----- Gender ----------------------------------------------------------->
            <tr>
                <td>GENDER</td>
                <td>Male <input type="radio" name="Gender" value="Male" />
                    Female <input type="radio" name="Gender" value="Female" />
                </td>
            </tr>

            <!----- Address ---------------------------------------------------------->

            <!----- City ---------------------------------------------------------->
            <tr>
                <td>CITY</td>
                <td><input type="text" name="City" maxlength="30" /> (max 30
                    characters a-z and A-Z)</td>
            </tr>

            <!----- Pin Code ---------------------------------------------------------->
            <tr>
                <td>PIN CODE</td>
                <td><input type="text" name="Pin_Code" maxlength="6" /> (6
                    digit number)</td>
            </tr>

            <!----- State ---------------------------------------------------------->
            <tr>
                <td>STATE</td>
                <td><input type="text" name="State" maxlength="30" /> (max 30
                    characters a-z and A-Z)</td>
            </tr>

            <!----- Country ---------------------------------------------------------->
            <tr>
                <td>COUNTRY</td>
                <td><input type="text" name="Country" value="India"
                    readonly="readonly" /></td>
            </tr>

            <tr>
                <td>PASSWORD</td>
                <td><input type="password" name="Password" maxlength="30"
                    min="8" /></td>
            </tr>

            <tr>
                <td>CONFIRM PASSWORD</td>
                <td><input type="password" name="Con_password" maxlength="30"
                    min="8" /></td>
            </tr>


            <!----- Submit and Reset ------------------------------------------------->
            <tr>
                <td colspan="2" align="center"><input type="submit"
                    value="SIGN UP"></td>
            </tr>

        </table>

    </form>

</body>
</html>

Java: RegisterServlet.java

`package com.train.seat.exchange;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.train.seat.exchange.dao.UserDAO;
import com.train.seat.exchange.dto.UserDTO;

public class RegisterServlet extends HttpServlet {

    public RegisterServlet() {
        System.out.println("RegisterServlet started");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        UserDTO user = new UserDTO();

        user.setfName(req.getParameter("First_Name"));
        user.setlName(req.getParameter("Last_Name"));
        user.setAge(Integer.parseInt("age"));
        user.setEmail(req.getParameter("Email_Id"));
        user.setMobileNum(Long.parseLong("Mobile_Number"));
        user.setGender(req.getParameter("Gender"));
        user.setCity(req.getParameter("City"));
        user.setState(req.getParameter("State"));
        user.setPinCode(Integer.parseInt("Pin_Code"));
        user.setCountry(req.getParameter("Country"));
        user.setPassword(req.getParameter("Password"));

        HttpSession session = req.getSession(true);

        UserDAO userdao = new UserDAO();
        userdao.registeruser(user);

        resp.sendRedirect("login.html");
    }
}`

web.xml:

    <?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    version="3.0">
    <display-name>TrainSeatExchange</display-name>
    <welcome-file-list>
        <welcome-file>signup.html</welcome-file>
    </welcome-file-list>
    <servlet>
        <servlet-name>RegisterServlet</servlet-name>
        <servlet-class>com.train.seat.exchange.RegisterServlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>RegisterServlet</servlet-name>
        <url-pattern>/rs</url-pattern>
    </servlet-mapping>

</web-app>

here is my error :

here is project structure

0 个答案:

没有答案