?? add.java
字號(hào):
/*
* Created on 2004-9-24
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package com.affice;
import oa.sys.*;
import oa.sys.Time;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
/**
****************************************************
*類名稱: Add<br>
*類功能: 增加公告信息<br>
*創(chuàng)建: 白偉明 2004年10月5日<br>
****************************************************
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class Add extends HttpServlet{
private HttpSession session=null;
private ResultSet rs=null;
private Statement stmt=null;
private String title,content,sqli,sqls;
private int temp=0,id;
public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException{
request.setCharacterEncoding("gb2312");//設(shè)定統(tǒng)一編碼樣式,解決中文顯示問題
response.setContentType("text/html; charset=gb2312");
Str str=new Str();//獲得字符串轉(zhuǎn)化類中的對(duì)象
Db db=new Db();//獲得數(shù)據(jù)庫連接對(duì)象
Time time=new Time();//獲得顯示時(shí)間類中的對(duì)象
PrintWriter out=response.getWriter();//獲得輸出流對(duì)象
session=request.getSession();//返回和客戶端關(guān)聯(lián)的Session
id=Integer.parseInt((String)session.getAttribute("id"));//獲得員工登陸的ID號(hào)
title=request.getParameter("title");//接收表單提交過來公告標(biāo)題
content=request.getParameter("content");//接收表單提交過來的公告內(nèi)容
title=str.inStr(title);//對(duì)標(biāo)題進(jìn)行字符串的格式轉(zhuǎn)化
content=str.inStr(content);
sqli="INSERT INTO affice(title,time,employeeid,content)"+
" VALUES('"+title+"','"+time.getYMD()+"',"+id+",'"+content+"')";
sqls="SELECT * FROM affice WHERE time='"+time.getYMD()+"'";
try {
stmt=db.getStmtread();
rs=stmt.executeQuery(sqls);//執(zhí)行判斷今日是否已經(jīng)發(fā)布了公告的SQL語句
if(!rs.next()){//如果今日還沒有發(fā)布公告
db.close();
stmt=db.getStmt();
temp=stmt.executeUpdate(sqli);//執(zhí)行插入的SQL語句
if(temp>0){
request.setAttribute("msg","發(fā)布成功");//通過"名-值"對(duì)的形式將信息保存在Request范圍內(nèi)
}else{
request.setAttribute("msg","發(fā)布失敗");
}
}else{
request.setAttribute("msg","今日已經(jīng)發(fā)布公告,不能再發(fā)布");
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
db.close();
//處理完客戶請(qǐng)求后,將請(qǐng)求轉(zhuǎn)發(fā)到相應(yīng)的JSP頁來顯示處理結(jié)果
RequestDispatcher dispatcher=request.getRequestDispatcher("add.jsp");
dispatcher.forward(request,response);
}
}
//doGet()方法的執(zhí)行效果和doPost()方法一樣
public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException{
doPost(request,response);
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -