?? 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 {
/**建立操作數(shù)據(jù)庫的對象*/
DbManage dbm = new DbManage();
/**保存返回的記錄集*/
ResultSet rs = null;
/**各種屬性*/
String deptId;
String deptName;
String deptFuze;
/**
* 構(gòu)造函數(shù)
*/
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"); //設(shè)置響應(yīng)屬性
InputStream is = request.getInputStream(); //接收客戶端的請求
DataInputStream dis = new DataInputStream(is); //這邊建立一個在本地接受數(shù)據(jù)的,用于去讀客戶端寫到流里面去的信息
//數(shù)據(jù)庫處理
try{
dbm.getConnection();
String sql = "select * from tab_dept";
rs = dbm.executeSelect(sql);
// 發(fā)送處理后的結(jié)果給手機(jī)
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
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -