📄 servletshowdept.java
字号:
package system.dept.contorl;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.sql.ResultSet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import db.DbManage;
/**
* 显示部门信息的SERVLET
* @author foxliucong
*
*/
public class ServletShowDept extends HttpServlet {
/**建立操作数据库的对象*/
DbManage dbm = new DbManage();
/**保存返回的记录集*/
ResultSet rs = null;
/**各种属性*/
String deptId;
String deptName;
String deptFuze;
/**
* 构造函数
*/
public ServletShowDept() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost( request, response);
}
/**
* The doPost method of the servlet. <br>
*
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html; charset=GBK"); //设置响应属性
InputStream is = request.getInputStream(); //接收客户端的请求
DataInputStream dis = new DataInputStream(is); //这边建立一个在本地接受数据的,用于去读客户端写到流里面去的信息
//数据库处理
try{
dbm.getConnection();
String sql = "select * from tab_dept";
rs = dbm.executeSelect(sql);
// 发送处理后的结果给手机
DataOutputStream dos = new DataOutputStream(response.getOutputStream()); //写到输出流中,让客户端去读
while(rs.next()){
deptId = rs.getString(1);
deptName = rs.getString(2);
deptFuze= rs.getString(3);
dos.writeUTF(deptId);//写到客户端去
dos.writeUTF(deptName);
dos.writeUTF(deptFuze);
}
}catch(Exception e){System.out.print(e); }
finally{
dbm.closeRs();
dbm.closeStmt();
dbm.closeConn();
}
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occure
*/
public void init() throws ServletException {
// Put your code here
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -