发消息servlet的处理

package fund.apply_pay_expenses;

import javax.servlet.http.*;
import javax.servlet.jsp.JspFactory;
import javax.servlet.jsp.PageContext;
import javax.servlet.*;

import com.jspsmart.upload.SmartUpload;

import java.io.* ;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;

import include.nseer_cookie.Email;
import include.nseer_cookie.counter;
import include.nseer_cookie.getFileLength;
import include.nseer_db.*;

public class check_oka extends HttpServlet {

public synchronized void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
HttpSession dbSession=request.getSession();
        JspFactory _jspxFactory=JspFactory.getDefaultFactory();
        PageContext pageContext = _jspxFactory.getPageContext(this,request,response,"",true,8192,true);
        ServletContext dbApplication=dbSession.getServletContext();
       
    try{
//          实例化

            HttpSession session=request.getSession();
            PrintWriter out = response.getWriter();

            ServletContext context=session.getServletContext();
            String path=context.getRealPath("/");
            counter count=new counter(dbApplication);
            SmartUpload mySmartUpload=new SmartUpload();
            mySmartUpload.setCharset("UTF-8");
            nseer_db_backup1 document_db = new nseer_db_backup1(dbApplication);
            nseer_db_backup1 document_db1 = new nseer_db_backup1(dbApplication);
            if(document_db.conn((String)dbSession.getAttribute("unit_db_name"))&&document_db1.conn((String)dbSession.getAttribute("unit_db_name"))){

   
            mySmartUpload.initialize(pageContext);
            String file_type=getFileLength.getFileType((String)session.getAttribute("unit_db_name"));
            long d=getFileLength.getFileLength((String)session.getAttribute("unit_db_name"));
            mySmartUpload.setMaxFileSize(d);
            mySmartUpload.setAllowedFilesList(file_type);

            mySmartUpload.upload();
            String[] file_name=new String[mySmartUpload.getFiles().getCount()];
            java.util.Date now = new java.util.Date();
            SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
            String time=formatter.format(now);//获取现在的年-月-日
            /*-----获取from表单中的参数----*/
            String name=mySmartUpload.getRequest().getParameter("name");//发送人
String title=mySmartUpload.getRequest().getParameter("title");//消息主题
String bio=mySmartUpload.getRequest().getParameter("bio");//发送内容
String name_id=mySmartUpload.getRequest().getParameter("name_id");//获取收件人的编号
//--------复选框----------
String email=mySmartUpload.getRequest().getParameter("cbxa");//电子邮件
String phone=mySmartUpload.getRequest().getParameter("cbxb");//手机短信
String in_message=mySmartUpload.getRequest().getParameter("cbxc");//内部消息

            if(phone!=null||email!=null||in_message!=null){
            String sql="insert into message(name,title,name_email,field,bio,email,phone,in_message) values('"+name+"','"+title+"','"+name_id+"','','"+bio+"','"+email+"','"+phone+"','"+in_message+"')";    
                document_db.executeUpdate(sql);
                String b[]=name_id.split("ж");//分解传过来的--收件人编号name_id
                String[] youjian_e =null;
                String youjian_yj="";//把邮件地址组合一个字符串
                String tel="";
                String[] path_e=null;
                for(int j=0;j<b.length;j++){
                String sqlq="select HUMAN_EMAIL, HUMAN_HOME_TEL from hr_file where HUMAN_ID='"+b[j]+"'";
                ResultSet rs1=document_db.executeQuery(sqlq);
                if(rs1.next()){
                youjian_yj +=rs1.getString("HUMAN_EMAIL")+"ж";
               
                youjian_e=new String[b.length];
                youjian_e =youjian_yj.split("ж");
                 
                    tel =rs1.getString("HUMAN_HOME_TEL");
                }
                }
               
               
            try{
            for(int i=0;i<mySmartUpload.getFiles().getCount();i++){
                com.jspsmart.upload.SmartFile file = mySmartUpload.getFiles().getFile(i);
                if (file.isMissing()){
                    file_name[i]="";
                    continue;
                    }
                String filename=file.getFileName();
                    file.saveAs(path+"erpPlatform/file_attachments/message" + filename);
                    String path_email=path+"erpPlatform/file_attachments/message" + filename;//邮件附件的全路径
                   
                     path_e=new String[mySmartUpload.getFiles().getCount()];
                   
                    path_e[i]=path_email;
            }
             if("1".equals(email)&&youjian_yj.equals("")==false){
              //发邮件
        Email e=new Email();
        e.send((String)dbSession.getAttribute("unit_db_name"),youjian_e,title,bio,path_e);
              }
              if("2".equals(phone)&&tel.equals("")==false){
              //电话
            String sql_phone="insert into message_phone(title,bio,phone,name) values('"+title+"','"+bio+"','"+tel+"','"+name+"')";
                document_db1.executeUpdate(sql_phone);
               System.out.print("发送短信");  
              }
              if("3".equals(in_message)){
              //内部消息
              System.out.print("发送内部消息");
              }
            out.print("{success:true, file:'成功'}");
            document_db.commit();
            document_db1.commit();
            document_db.close();
            document_db1.close();
           
            }
            catch(Exception ex){
                out.print("{success:true, file:'失败,<br>检查文件大小或类型是否在范围内'}");
            }finally{
    out.close();
    }
            }else{
out.print("{success:true, file:'失败,<br>没有选择发送类型'}");
}
            }else{
                response.sendRedirect("error_conn.htm");
            }
            }catch (Exception ex){
      ex.printStackTrace();
    }
}
}

你可能感兴趣的:(sql,jsp,servlet,J#)