如何将请求从jsp页面转移到dao类

时间:2019-03-08 14:49:29

标签: java jsp servlets java-ee jdbc

这是我的jsp页面

     **<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" isELIgnored="false"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1>Driver registration</h1>
<form action="${pageContext.request.contextPath}/driverdao">
<table>
<tr>
<th>Id</th>
<th><input type="text" name="Id" value="${Driverreg.did}"></th>
</tr>
<tr>
<tr>
<th>Name</th>
<th><input type="text" name="Name" value="${Driverreg.dname}"></th>
</tr>

<th>Address</th>
<th><input type="text" name="Address" value="${Driverreg.daddress}"></th>
</tr>   
<tr>
<th>dgtype</th>
<th><input type="text" name="dgtype" value="${Driverreg.dgtype}"></th>
</tr>
<tr>
<th>dgovtidno</th>
<th><input type="text" name="dgovtidno" value="${Driverreg.dgovtidno}"></th>
</tr>   
<tr><th><input type="submit" value="Save"></th></tr>
</table>
</form>
</body>
</html> **

这是我的道课

package dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import connection.Connect;
import model.Driverreg;

public class driverdao {

    private Connection connection;

    public driverdao() throws Exception {
        connection = Connect.getConnection();
    }

    public void adddriver(Driverreg d)
    {
        try {
            PreparedStatement p=
            connection.prepareStatement("insert into drireg(did,dname,daddress,dgovtidno,dgtype)values(?,?,?,?,?)");

            p.setInt(1, d.getDid());
            p.setString(2, d.getDname());
            p.setString(3, d.getDaddress());
            p.setInt(4, d.getDgovtidno());
            p.setString(5, d.getDgtype());

        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

我已经创建了该jsp页面用于驱动程序注册,并且想将在表单中输入的数据保存到数据库中,为此我已经在dao类中编写了adddriver方法。我已经创建了pojo Drireg,并用于连接mysql Connect类。 当用户单击“保存”按钮时,请求应转到此dao类,但是在执行这些操作时出现错误。该怎么办?

我想在用户单击保存按钮到数据库时保存数据

错误是

HTTP Status 404 - /selflearn/dao/driverdao


type Status report

message /selflearn/dao/driverdao

description The requested resource is not available.


Apache Tomcat/8.0.9

0 个答案:

没有答案