⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 insertmesservlet.java

📁 oa源码哈
💻 JAVA
字号:
package edu.scfc;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.sql.*;
public class InsertMesServlet extends HttpServlet {
    String at;
    private Connection con;
    private Statement st;
    private ResultSet rs;
    private static final String CONTENT_TYPE = "text/html; charset=GBK";
    ConnDB connDB=new ConnDB();
    //Initialize global variables
    public void init() throws ServletException {
    }

    //Process the HTTP Get request
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws
            ServletException, IOException {
        response.setContentType(CONTENT_TYPE);
        request.setCharacterEncoding("GBK");
        response.setCharacterEncoding("GBK");
        PrintWriter out = response.getWriter();
        HttpSession send=request.getSession();
        String sendperson=send.getAttribute("realName").toString();
        String sendDept=send.getAttribute("dept").toString();

        String ss=request.getParameter("sendto");
        String Title=request.getParameter("标题");
        String content=request.getParameter("content");
        Vector vvv=new Vector();
        vvv=this.getVc(ss,out);
        for(int i=0;i<vvv.size();i++)
        {
         String sss=vvv.get(i).toString();
         this.select(sss,Title,content,sendperson,sss,sendDept,out);
        }
        out.print(
                    "<script>alert('发送信息成功....');location.href='sendRegister.jsp';</script>");
    }
    public Vector getVc(String aa,PrintWriter out)
    {
        Vector v=new Vector();
         while(aa.contains("|"))
         {
             int j = aa.indexOf("|");
             at = aa.substring(0, aa.indexOf("|"));
             aa= aa.substring(j + 1);
              v.add(at);
         }
        return v;
    }
    public void select(String ss,String Title,String Content,String SendUName,String ReceiveUName,String SendDept,PrintWriter out)
    {
        this.con=connDB.getConnection();
        try {
            this.st = con.createStatement();
             this.rs=st.executeQuery("select Dept from TB_Personnel where RealName='"+ss+"'");
             while(rs.next())
             {
                 String detp=rs.getString("Dept");
                 st.executeUpdate("insert into TB_SendMes(Title,Content,SendUName,ReceiveDept,ReceiveUName) values('"+Title+"','"+Content+"','"+SendUName+"','"+detp+"','"+ReceiveUName+"')");
                 st.executeUpdate("insert into TB_ReceiveMes(Title,Content,ReceiveUName,SendDept,SendUName) values('"+Title+"','"+Content+"','"+ReceiveUName+"','"+SendDept+"','"+SendUName+"')") ;
             }
        } catch (SQLException ex)
        {
            System.out.println("-->"+ex.getMessage());
        }



    }

    //Process the HTTP Post request
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws
            ServletException, IOException {
        doGet(request, response);
    }

    //Clean up resources
    public void destroy() {
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -