起步软件技术论坛
搜索
 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 1430|回复: 0

[分享] web应用发布集成及电子key图片获取作为电子签名

[复制链接]

50

主题

483

帖子

1163

积分

金牌会员

Rank: 6Rank: 6

积分
1163
QQ
发表于 2013-11-26 09:02:28 | 显示全部楼层 |阅读模式
1、web集成采用简单的web应用,没有使用x5的集成方法,就是直接发布到tomcat下面,进行获取,不用直接上源码。
  1. public class test{

  2.   public String ClassString=null;
  3.   public String ConnectionString=null;
  4.   public String UserName=null;
  5.   public String PassWord=null;

  6.   public Connection Conn;
  7.   public Statement Stmt;


  8.   public iDBManager2000() {

  9.          
  10.           InputStream in  = null;
  11.           try {
  12.                 File directory = new File("");
  13.                 String path = directory.getAbsolutePath();
  14.                 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();   
  15.                 DocumentBuilder builder = factory.newDocumentBuilder();  
  16.                 System.out.println(path);
  17.                 in = new FileInputStream(new File(path.replace("\", "/")+"/../conf/server.xml"));
  18.                 Document document = builder.parse(in);
  19.                 Element element = document.getDocumentElement();
  20.                 NodeList nodes = element.getElementsByTagName("Host");   
  21.                 for(int i=0;i<nodes.getLength();i++){   
  22.                         Element bookElement = (Element) nodes.item(i);   
  23.                         NodeList childNodes = bookElement.getChildNodes();
  24.                         for(int j=0;j<childNodes.getLength();j++){
  25.                                 if(childNodes.item(j).getNodeName().equalsIgnoreCase("Context")){
  26.                                         NodeList childNodes1 = childNodes.item(j).getChildNodes();
  27.                                         for(int k=0;k<childNodes1.getLength();k++){
  28.                                                 if(childNodes1.item(k).getNodeName().equalsIgnoreCase("Resource")){
  29.                                                         Element resourceElement = (Element)childNodes1.item(k);
  30.                                                         if(resourceElement.getAttribute("name").equalsIgnoreCase("oa")){
  31.                                                                 ClassString = resourceElement.getAttribute("driverClassName");
  32.                                                                 ConnectionString = resourceElement.getAttribute("url");
  33.                                                                 if(ClassString.equals("net.sourceforge.jtds.jdbc.Driver")){
  34.                                                                         ClassString = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
  35.                                                                         String [] str = ConnectionString.split("//");
  36.                                                                         String ip = str[1].split("/")[0];
  37.                                                                         String dataBase = str[1].split("/")[1];
  38.                                                                         ConnectionString = "jdbc:microsoft:sqlserver://"+ip+"; DatabaseName="+dataBase;       
  39.                                                                 }
  40.                                                                 UserName = resourceElement.getAttribute("username");
  41.                                                                 PassWord = resourceElement.getAttribute("password");
  42.                                                                 System.out.println(ClassString);
  43.                                                                 System.out.println(ConnectionString);
  44.                                                         }
  45.                                                 }
  46.                                         }
  47.                                 }
  48.                         }
  49.                  }
  50.         } catch (Exception e) {
  51.                 e.printStackTrace();
  52.         }
  53.    
  54.   }

  55.   public boolean OpenConnection()
  56.   {
  57.    boolean mResult=true;
  58.    try
  59.    {
  60.      Class.forName(ClassString);
  61.      if ((UserName==null) && (PassWord==null))
  62.      {
  63.        Conn= DriverManager.getConnection(ConnectionString);
  64.      }
  65.      else
  66.      {
  67.        Conn= DriverManager.getConnection(ConnectionString,UserName,PassWord);
  68.      }
  69.      Stmt=Conn.createStatement();
  70.      mResult=true;
  71.    }
  72.    catch(Exception e)
  73.    {
  74.      System.out.println(e.toString());
  75.      mResult=false;
  76.    }
  77.    return (mResult);
  78.   }

  79.   public void CloseConnection()
  80.   {
  81.    try
  82.    {
  83.      Stmt.close();
  84.      Conn.close();
  85.    }
  86.    catch(Exception e)
  87.    {
  88.      System.out.println(e.toString());
  89.    }
  90.   }
  91.   public String GetDateTime()
  92.   {
  93.    Calendar cal  = Calendar.getInstance();
  94.    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  95.    String mDateTime=formatter.format(cal.getTime());
  96.    return (mDateTime);
  97.   }

  98.   public  java.sql.Date  GetDate()
  99.   {
  100.     java.sql.Date mDate;
  101.     Calendar cal  = Calendar.getInstance();
  102.     SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
  103.     String mDateTime=formatter.format(cal.getTime());
  104.     return (java.sql.Date.valueOf(mDateTime));
  105.   }

  106.   public int GetMaxID(String vTableName,String vFieldName)
  107.   {
  108.    int mResult=0;
  109.    String mSql=new String();
  110.    mSql = "select max("+vFieldName+")+1 as MaxID from " + vTableName;
  111.    if (OpenConnection())
  112.    {
  113.      try
  114.      {
  115.        ResultSet result=ExecuteQuery(mSql);
  116.        if (result.next())
  117.        {
  118.          mResult=result.getInt("MaxID");

  119.        }
  120.        result.close();
  121.      }
  122.      catch(Exception e)
  123.      {
  124.        System.out.println(e.toString());
  125.      }
  126.      CloseConnection();
  127.    }
  128.    return (mResult);
  129. }

  130.   public ResultSet ExecuteQuery(String SqlString)
  131.   {
  132.     ResultSet result=null;
  133.     try
  134.     {
  135.       result=Stmt.executeQuery(SqlString);
  136.     }
  137.     catch(Exception e)
  138.     {
  139.       System.out.println(e.toString());
  140.     }
  141.     return (result);
  142.   }

  143.   public int ExecuteUpdate(String SqlString)
  144.   {
  145.     int result=0;
  146.     try
  147.     {
  148.       result=Stmt.executeUpdate(SqlString);
  149.     }
  150.     catch(Exception e)
  151.     {
  152.       System.out.println(e.toString());
  153.     }
  154.     return (result);
  155.   }
  156.   

  157.   public void PutAtBlob(BLOB vField,byte[]SignatureBody) throws IOException{
  158.     try{
  159.       int vSize = SignatureBody.length;
  160.       OutputStream outstream = vField.getBinaryOutputStream();
  161.       outstream.write(SignatureBody,0, vSize);
  162.       outstream.flush();
  163.       outstream.close();
  164.     }catch(SQLException e){
  165.             System.out.println(e.toString());
  166.     }
  167.   }
  168.   

  169.   public String GetAtBlob(java.sql.Blob vField, int vSize) throws
  170.         SQLException,
  171.         IOException {
  172.         String mSignData = null;
  173.         try {
  174.                 byte[] mTmp = new byte[vSize];
  175.                 InputStream instream = vField.getBinaryStream();
  176.                 instream.read(mTmp, 0, vSize);
  177.                 mSignData = new String(mTmp);
  178.                 instream.close();
  179.                 mSignData = mSignData;
  180.         }
  181.         catch (IOException e) {
  182.                 System.out.println(e.toString());
  183.         }
  184.         return (mSignData);
  185. }
  186. }
复制代码
  1.         /*
  2.                 out.println("====");
  3.                 String imgFile = "d:\\111.jpg";//待处理的图片
  4.         InputStream in = null;
  5.         byte[] data = null;
  6.         //读取图片字节数组
  7.           try {
  8.                         in = new FileInputStream(imgFile);        
  9.                             data = new byte[in.available()];
  10.                             in.read(data);
  11.                             in.close();
  12.                 } catch (FileNotFoundException e) {
  13.                         e.printStackTrace();
  14.                 } catch (java.io.IOException e) {
  15.                         e.printStackTrace();
  16.                 }
  17.                 */
  18.         //上面是一个测试用例
  19.         String path = request.getContextPath();
  20.         String basePath = request.getScheme() + "://"
  21.                         + request.getServerName() + ":" + request.getServerPort()
  22.                         + path + "/";
  23.         DBstep.test ObjConnBean = new DBstep.test();
  24.         //得到图像BASE64编码
  25.           String sSeal = request.getParameter("SEAL");
  26.         System.out.println(sSeal);
  27.           //得到证书DN
  28.           String sCertDN = request.getParameter("CERTDN");
  29.           sCertDN= new String(sCertDN.getBytes("ISO8859_1"),"GBK");
  30.           //将图像BASE64解码
  31.           BASE64Decoder bdr = new BASE64Decoder();
  32.         byte[] bSeal = bdr.decodeBuffer(sSeal);
  33. //上面是获取别人提供的接口方法,视情况而定
  34.         String[] str = sCertDN.split(",");
  35.         String name = str[3].substring(4, str[3].length());
  36.         String dept = str[2].substring(4, str[2].length());
  37.         String code = str[4].substring(4, str[4].length());
  38.         System.out.println(name+dept+code);
  39.         String sql = "select spersonID,sparent from sa_oporg  where scode='"+ code + "'";
  40.         String personID = null;
  41.         byte[] SignatureBody = null;
  42.         String mSignature = null;
  43.         if (ObjConnBean.OpenConnection()) {
  44.                 try {
  45.                         ResultSet res = ObjConnBean.ExecuteQuery(sql);
  46.                         if (res.next()) {
  47.                                 personID = res.getString("spersonID");
  48.                                 String sqlD = "select sname from sa_oporg where sid='"+ res.getString("sparent") + "' ";
  49.                                 ResultSet res1 = ObjConnBean.ExecuteQuery(sqlD);
  50.                                 out.println(sqlD);
  51.                                 if (res1.next()) {
  52.                                         if (res1.getString("sname").equals(dept)) {         
  53.                                                         Statement stmt = null;
  54.                                                         stmt = ObjConnBean.Conn.createStatement();
  55.                                                         OracleResultSet update1 = (OracleResultSet) stmt.executeQuery("select FSIGNATURE from AP_PersonSignature Where fid='"
  56.                                                                                         + personID + "' for update");
  57.                                                         if (update1.next()) {
  58.                                                                 try {
  59.                                                                         ObjConnBean.PutAtBlob(((oracle.jdbc.OracleResultSet) update1).getBLOB("FSIGNATURE"),bSeal);
  60.                                                                         out.print("ESS0");
  61.                                                                 } catch (IOException e) {
  62.                                                                         out.print("ESS1");
  63.                                                                 } finally {
  64.                                                                         stmt.close();
  65.                                                                 }
  66.                                                         }else {
  67.                                                         String insertSql = "insert into AP_PersonSignature(FID,VERSION,FSIGNATURE) values ('"+ personID + "',0,empty_blob() )";
  68.                                                         ObjConnBean.ExecuteUpdate(insertSql);
  69.                                                         stmt = ObjConnBean.Conn.createStatement();
  70.                                                         OracleResultSet update = (OracleResultSet) stmt.executeQuery("select FSIGNATURE from AP_PersonSignature Where fid='"
  71.                                                                                         + personID + "' for update");
  72.                                                         if (update.next()) {
  73.                                                                 try {
  74.                                                                         ObjConnBean.PutAtBlob(((oracle.jdbc.OracleResultSet) update).getBLOB("FSIGNATURE"),bSeal);
  75.                                                                         out.print("ESS0");
  76.                                                                 } catch (IOException e) {
  77.                                                                         out.print("ESS1");
  78.                                                                 } finally {
  79.                                                                         stmt.close();
  80.                                                                 }
  81.                                                         }
  82.                                                 }
  83.                                         } else {
  84.                                                 out.print("ESS1");
  85.                                         }
  86.                                 }
  87.                         }
  88.                 } catch (SQLException e) {
  89.                         System.out.println(e.toString());
  90.                 } finally {
  91.                         ObjConnBean.CloseConnection();
  92.                 }
  93.         }
  94. %>
复制代码
完整的例子:
可能存在bug,仅供参考!!互相学习!


CA.zip

9.72 KB, 下载次数: 901

例子

评分

参与人数 1 +13 收起 理由
jishuang + 13 赞一个!

查看全部评分

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|X3技术论坛|Justep Inc.    

GMT+8, 2024-5-18 14:43 , Processed in 0.071614 second(s), 30 queries .

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表