1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| package com.xiaoguan.oa.index;
import com.xiaoguan.oa.utils.DBUtil; import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.PrintWriter; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException;
public class DetailServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.setContentType("text/html;charset=UTF-8"); PrintWriter out=resp.getWriter(); String deptno = req.getParameter("deptno"); Connection conn=null; PreparedStatement ps=null; ResultSet rs=null; out.print("<!DOCTYPE html>"); out.print("<html lang='ch'>"); out.print(" <head>"); out.print(" <meta charset='UTF-8'>"); out.print(" <title>部门详情</title>"); out.print(" </head>"); out.print(" <body>"); out.print(" <h1>部门详情</h1>"); out.print(" <hr>");
try { conn= DBUtil.getConnection(); String sql="select deptno,dname,loc from dept where deptno=?"; ps=conn.prepareStatement(sql); ps.setString(1,deptno); rs=ps.executeQuery(); if(rs.next()){ String dname = rs.getString("dname"); String loc = rs.getString("loc"); out.print(" 部门编号<input type='text' value='"+deptno+"' readonly/><br>"); out.print(" 部门名称<input type='text' value='"+dname+"' readonly/><br>"); out.print(" 部门位置<input type='text' value='"+loc+"' readonly/><br>"); } } catch (SQLException e) { e.printStackTrace(); }finally { DBUtil.close(conn,ps,rs); } out.print(" <input type='button' value='后退' onclick='window.history.back()'>"); out.print(" </body>"); out.print("</html>"); } }
|