Add.java
上传用户:sxwtmm
上传日期:2022-08-11
资源大小:2183k
文件大小:2k
- /*
- * 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.emstate;
- import oa.sys.*;
- import java.io.IOException;
- import java.sql.*;
- import javax.servlet.*;
- import javax.servlet.http.*;
- /**
- ****************************************************
- *类名称: Add<br>
- *类功能: 增加状态信息<br>
- *创建: 白伟明 2004年9月25日<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 Statement stmt=null;
- private ResultSet rs=null;
- private String name,explain,sqli,sqls;
- private int temp=0;
-
- public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException{
- request.setCharacterEncoding("gb2312");
- response.setContentType("text/html; charset=gb2312");
- Str str=new Str();
- Db db=new Db();
- session=request.getSession();
- name=request.getParameter("name");
- explain=request.getParameter("explain");
- name=str.inStr(name);
- explain=str.inStr(explain);
- sqli="INSERT INTO emstate(name,explain) VALUES('"+name+"','"+explain+"')";
- sqls="SELECT * FROM emstate WHERE name='"+name+"'";
- stmt=db.getStmtread();
- try {
- rs=stmt.executeQuery(sqls);
- //查询状态是否存在
- if(rs.next()){
- session.setAttribute("depmsg","该状态已存在");
- }else{
- db.close();
- //添加状态
- stmt=db.getStmt();
- temp=stmt.executeUpdate(sqli);
- if(temp>0){
- session.setAttribute("depmsg","添加成功");
- }else{
- session.setAttribute("depmsg","添加失败");
- }
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }finally{
- db.close();
- RequestDispatcher dispatcher=request.getRequestDispatcher("add.jsp");
- dispatcher.forward(request,response);
- }
-
- }
- public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException{
- doPost(request,response);
- }
- }