|
1、web集成采用简单的web应用,没有使用x5的集成方法,就是直接发布到tomcat下面,进行获取,不用直接上源码。- public class test{
- public String ClassString=null;
- public String ConnectionString=null;
- public String UserName=null;
- public String PassWord=null;
- public Connection Conn;
- public Statement Stmt;
- public iDBManager2000() {
-
-
- InputStream in = null;
- try {
- File directory = new File("");
- String path = directory.getAbsolutePath();
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- DocumentBuilder builder = factory.newDocumentBuilder();
- System.out.println(path);
- in = new FileInputStream(new File(path.replace("\", "/")+"/../conf/server.xml"));
- Document document = builder.parse(in);
- Element element = document.getDocumentElement();
- NodeList nodes = element.getElementsByTagName("Host");
- for(int i=0;i<nodes.getLength();i++){
- Element bookElement = (Element) nodes.item(i);
- NodeList childNodes = bookElement.getChildNodes();
- for(int j=0;j<childNodes.getLength();j++){
- if(childNodes.item(j).getNodeName().equalsIgnoreCase("Context")){
- NodeList childNodes1 = childNodes.item(j).getChildNodes();
- for(int k=0;k<childNodes1.getLength();k++){
- if(childNodes1.item(k).getNodeName().equalsIgnoreCase("Resource")){
- Element resourceElement = (Element)childNodes1.item(k);
- if(resourceElement.getAttribute("name").equalsIgnoreCase("oa")){
- ClassString = resourceElement.getAttribute("driverClassName");
- ConnectionString = resourceElement.getAttribute("url");
- if(ClassString.equals("net.sourceforge.jtds.jdbc.Driver")){
- ClassString = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
- String [] str = ConnectionString.split("//");
- String ip = str[1].split("/")[0];
- String dataBase = str[1].split("/")[1];
- ConnectionString = "jdbc:microsoft:sqlserver://"+ip+"; DatabaseName="+dataBase;
- }
- UserName = resourceElement.getAttribute("username");
- PassWord = resourceElement.getAttribute("password");
- System.out.println(ClassString);
- System.out.println(ConnectionString);
- }
- }
- }
- }
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- }
- public boolean OpenConnection()
- {
- boolean mResult=true;
- try
- {
- Class.forName(ClassString);
- if ((UserName==null) && (PassWord==null))
- {
- Conn= DriverManager.getConnection(ConnectionString);
- }
- else
- {
- Conn= DriverManager.getConnection(ConnectionString,UserName,PassWord);
- }
- Stmt=Conn.createStatement();
- mResult=true;
- }
- catch(Exception e)
- {
- System.out.println(e.toString());
- mResult=false;
- }
- return (mResult);
- }
-
- public void CloseConnection()
- {
- try
- {
- Stmt.close();
- Conn.close();
- }
- catch(Exception e)
- {
- System.out.println(e.toString());
- }
- }
- public String GetDateTime()
- {
- Calendar cal = Calendar.getInstance();
- SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- String mDateTime=formatter.format(cal.getTime());
- return (mDateTime);
- }
- public java.sql.Date GetDate()
- {
- java.sql.Date mDate;
- Calendar cal = Calendar.getInstance();
- SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
- String mDateTime=formatter.format(cal.getTime());
- return (java.sql.Date.valueOf(mDateTime));
- }
- public int GetMaxID(String vTableName,String vFieldName)
- {
- int mResult=0;
- String mSql=new String();
- mSql = "select max("+vFieldName+")+1 as MaxID from " + vTableName;
- if (OpenConnection())
- {
- try
- {
- ResultSet result=ExecuteQuery(mSql);
- if (result.next())
- {
- mResult=result.getInt("MaxID");
- }
- result.close();
- }
- catch(Exception e)
- {
- System.out.println(e.toString());
- }
- CloseConnection();
- }
- return (mResult);
- }
- public ResultSet ExecuteQuery(String SqlString)
- {
- ResultSet result=null;
- try
- {
- result=Stmt.executeQuery(SqlString);
- }
- catch(Exception e)
- {
- System.out.println(e.toString());
- }
- return (result);
- }
- public int ExecuteUpdate(String SqlString)
- {
- int result=0;
- try
- {
- result=Stmt.executeUpdate(SqlString);
- }
- catch(Exception e)
- {
- System.out.println(e.toString());
- }
- return (result);
- }
-
-
- public void PutAtBlob(BLOB vField,byte[]SignatureBody) throws IOException{
- try{
- int vSize = SignatureBody.length;
- OutputStream outstream = vField.getBinaryOutputStream();
- outstream.write(SignatureBody,0, vSize);
- outstream.flush();
- outstream.close();
- }catch(SQLException e){
- System.out.println(e.toString());
- }
- }
-
-
- public String GetAtBlob(java.sql.Blob vField, int vSize) throws
- SQLException,
- IOException {
- String mSignData = null;
- try {
- byte[] mTmp = new byte[vSize];
- InputStream instream = vField.getBinaryStream();
- instream.read(mTmp, 0, vSize);
- mSignData = new String(mTmp);
- instream.close();
- mSignData = mSignData;
- }
- catch (IOException e) {
- System.out.println(e.toString());
- }
- return (mSignData);
- }
- }
复制代码- /*
- out.println("====");
- String imgFile = "d:\\111.jpg";//待处理的图片
- InputStream in = null;
- byte[] data = null;
- //读取图片字节数组
- try {
- in = new FileInputStream(imgFile);
- data = new byte[in.available()];
- in.read(data);
- in.close();
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (java.io.IOException e) {
- e.printStackTrace();
- }
- */
- //上面是一个测试用例
- String path = request.getContextPath();
- String basePath = request.getScheme() + "://"
- + request.getServerName() + ":" + request.getServerPort()
- + path + "/";
- DBstep.test ObjConnBean = new DBstep.test();
- //得到图像BASE64编码
- String sSeal = request.getParameter("SEAL");
- System.out.println(sSeal);
- //得到证书DN
- String sCertDN = request.getParameter("CERTDN");
- sCertDN= new String(sCertDN.getBytes("ISO8859_1"),"GBK");
- //将图像BASE64解码
- BASE64Decoder bdr = new BASE64Decoder();
- byte[] bSeal = bdr.decodeBuffer(sSeal);
- //上面是获取别人提供的接口方法,视情况而定
- String[] str = sCertDN.split(",");
- String name = str[3].substring(4, str[3].length());
- String dept = str[2].substring(4, str[2].length());
- String code = str[4].substring(4, str[4].length());
- System.out.println(name+dept+code);
- String sql = "select spersonID,sparent from sa_oporg where scode='"+ code + "'";
- String personID = null;
- byte[] SignatureBody = null;
- String mSignature = null;
- if (ObjConnBean.OpenConnection()) {
- try {
- ResultSet res = ObjConnBean.ExecuteQuery(sql);
- if (res.next()) {
- personID = res.getString("spersonID");
- String sqlD = "select sname from sa_oporg where sid='"+ res.getString("sparent") + "' ";
- ResultSet res1 = ObjConnBean.ExecuteQuery(sqlD);
- out.println(sqlD);
- if (res1.next()) {
- if (res1.getString("sname").equals(dept)) {
- Statement stmt = null;
- stmt = ObjConnBean.Conn.createStatement();
- OracleResultSet update1 = (OracleResultSet) stmt.executeQuery("select FSIGNATURE from AP_PersonSignature Where fid='"
- + personID + "' for update");
- if (update1.next()) {
- try {
- ObjConnBean.PutAtBlob(((oracle.jdbc.OracleResultSet) update1).getBLOB("FSIGNATURE"),bSeal);
- out.print("ESS0");
- } catch (IOException e) {
- out.print("ESS1");
- } finally {
- stmt.close();
- }
- }else {
- String insertSql = "insert into AP_PersonSignature(FID,VERSION,FSIGNATURE) values ('"+ personID + "',0,empty_blob() )";
- ObjConnBean.ExecuteUpdate(insertSql);
- stmt = ObjConnBean.Conn.createStatement();
- OracleResultSet update = (OracleResultSet) stmt.executeQuery("select FSIGNATURE from AP_PersonSignature Where fid='"
- + personID + "' for update");
- if (update.next()) {
- try {
- ObjConnBean.PutAtBlob(((oracle.jdbc.OracleResultSet) update).getBLOB("FSIGNATURE"),bSeal);
- out.print("ESS0");
- } catch (IOException e) {
- out.print("ESS1");
- } finally {
- stmt.close();
- }
- }
- }
- } else {
- out.print("ESS1");
- }
- }
- }
- } catch (SQLException e) {
- System.out.println(e.toString());
- } finally {
- ObjConnBean.CloseConnection();
- }
- }
- %>
复制代码 完整的例子:
可能存在bug,仅供参考!!互相学习!
|
评分
-
查看全部评分
|