Mình đang làm bt về tạo trang web cho phép nhập, sửa và xoá thông tin thí sinh dự thi ( bào gồm các thông tin: sbd, họ tên, ngày sinh, giới tính,…)
Khi mình chạy trang để cho người dùng nhập vào rồi dùng method “post” để nhảy sang Nhap.jsp (để lấy thông tin trên cho vào database ) thì nó lại là trang trắng trơn ( mình có dùng lệnh if để nếu nó add thành công thì hiện chữ OK).
Nhap.jsp:
<%@page import="java.sql.Date"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="Database_QLTS.DB_Process"%>
<%@page import="Database_QLTS.Thisinh"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Nhập thông tin thí sinh</title>
    </head>
    <body>
        <%           
            DB_Process dp = new DB_Process();
            String sbd = request.getParameter("txt_sbd");
            String ht = request.getParameter("txt_ht");
            String ns = request.getParameter("txt_ngaysinh");
            //SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
           //sdf.setLenient(false);
            boolean gt = true;
            if(request.getParameter("rb_gt")=="Nam") gt=true;
            if(request.getParameter("rb_gt")=="Nữ") gt=false;
            String qq = request.getParameter("txt_que");
            double dt = Double.parseDouble(request.getParameter("txt_dt"));
            double dl = Double.parseDouble(request.getParameter("txt_dl"));
            double dh = Double.parseDouble(request.getParameter("txt_dh"));
            String sp = request.getParameter("txt_sp");
            if(dp.InsertTS(sbd, ht, ns, gt, qq, dt, dl, dh, sp))
            {%>OK<%}          
            %>
    </body>
</html>
DB_Process:
package Database_QLTS;
import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
public class DB_Process {
// get danh sách thí sinh
public ArrayList<Thisinh> getListThisinh()
throws SQLException {
Connection connection = DB_Connection.getCon();
String sql = "SELECT * FROM qlts";
PreparedStatement ps = connection.prepareCall(sql);
ResultSet rs = ps.executeQuery();
ArrayList<Thisinh> list = new ArrayList<>();
while (rs.next()) {
Thisinh ts = new Thisinh();
ts.setSBD(rs.getString("SBD"));
ts.setHoten(rs.getString("Hoten"));
ts.setNS(rs.getDate("NS"));
ts.setGT(rs.getBoolean("GT"));
ts.setQQ(rs.getString("QQ"));
ts.setDT((int) rs.getDouble("DT"));
ts.setDL((int) rs.getDouble("DL"));
ts.setDH((int) rs.getDouble("DH"));
ts.setSBD(rs.getString("SP"));
list.add(ts);
}
return list;
}
public boolean InsertTS(String sbd, String ht, String ns, boolean gt, String qq, double dt, double dl, double dh, String sp){
    Connection cn = DB_Connection.getCon();
    String sql ="INSERT INTO qlts(SBD,Hoten,NS,GT,QQ,DT,DL,DH,SP) VALUES ('"+sbd+"','"+ht+"',"+ns+","+gt+",'"+qq+"',"+dt+","+dl+","+dh+",'"+sp+"')";
    try{
        PreparedStatement ps = cn.prepareStatement(sql);
        ps.executeUpdate();
    }
    catch(Exception e)
    {     
        e.printStackTrace();
    }
    return false;
}
/*public static void UpdateTS(String sbd, String ht, Date ns, Boolean gt, String qq, double dt, double dl, double dh, String sp){
    Connection cn = DB_Connection.getCon();
    String tbname="qlts";
    String sql ="Update "+tbname+"Set `SBD`='"+sbd+"',`Hoten`='"+ht+"',`NS`='"+ns+"',`GT`="+gt",`QQ`='"+qq+"',`DT`="+dt",`DL`="+dl",`DH`="+dh",`SP`='"+sp"'";
    try{
        PreparedStatement ps = cn.prepareStatement(sql);
        ps.executeUpdate();
    }
    catch(Exception e)
    {     
    }
}
*/
public void DeleteTS(String sbd, String ht, Date ns, Boolean gt, String qq, double dt, double dl, double dh, String sp){
    Connection cn = DB_Connection.getCon();
    String tbname="qlts";
    String sql ="Delete from"+tbname+"Where `SBD` ="+sbd;
    try{
        PreparedStatement ps = cn.prepareStatement(sql);
        ps.executeUpdate();
    }
    catch(Exception e)
    {     
    }
}
}
Trang nhập thông tin:
<%-- 
    Document   : index
    Created on : Jun 6, 2019, 1:03:49 PM
    Author     : Microsoft Windows
--%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.sql.Date" %>
<%@page import="Database_QLTS.*"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Thông tin thí sinh</title>
    <h1>Thông tin các thí sinh dự thi</h1>
    </head>
    <body>
        <form action="Nhap.jsp" method="POST">
        <table border="1">
            <thead>
                <tr>
                    <th>Số báo danh</th>
                    <th><input type="text" name="txt_sbd" value="" /> </th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>Họ và tên</td>
                    <td><input type="text" name="txt_ht" value="" /> </td>
                </tr>
                <tr>
                    <td>Ngày sinh</td>
                    <td> <input type="text" name="txt_ngaysinh" value="" placeholder="ngay/thang/nam"  /></td>
                </tr>
                <tr>
                    <td>Giới tính</td>
                    <td><input type="radio" name="rb_gt" value="Nam"/>Nam <input type="radio" name="rb_gt" value="Nữ"/>Nữ</td>
                </tr>
                <tr>
                    <td>Quê quán</td>
                    <td> <input type="text" name="txt_que" value="" /></td>
                </tr>
                <tr>
                    <td>Điểm Toán</td>
                    <td><input type="text" name="txt_dt" value="" /></td>
                </tr>
                <tr>
                    <td>Điểm Lí</td>
                    <td><input type="text" name="txt_dl" value="" /></td>
                </tr>
                <tr>
                    <td>Điểm Hoá</td>
                    <td><input type="text" name="txt_dh" value="" /></td>
                </tr>
                <tr>
                    <td>Số Phòng Thi</td>
                    <td><input type="text" name="txt_sp" value="" /></td>
                </tr>                  
                <tr>
                     <td><input type="submit" value="Thêm Thí Sinh" name="lb_themTS" /></td>
                </tr>
            </tbody>
        </table>
        </form>
    </body>
</html>
        
      
    
    83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?