Common instance code for java data encryption and decryption

  • 2020-07-21 08:00:12
  • OfStack

This is an jsp file about key query, which accepts the data of the parent file and encrypts it, puts it into the Map collection, and submits it to the xdoc file through the form form. However, this approach is to meet the requirements of the company, the content of the framework is cumbersome; The next article introduces a simple and common approach that doesn't require much of an environment to build.


<br><br><%@ page language="java" contentType="text/html; charset=utf-8"
 pageEncoding="utf-8"%>
<%@page import="java.io.IOException"%>
<%@page import="java.util.ArrayList"%> 
<%@page import="java.util.List"%>
<%@page import="java.util.HashMap"%>
<%@page import="java.util.Map"%>
<%@page import="java.sql.*"%>
<%@page import="java.util.*"%>
 <%@page import="java.sql.ResultSet"%> 
 <%@page import="combiz.system.IBOSrvUtil"%> 
 <%@page import="combiz.ui.epassmanager.entitys.Base64"%>
 
<%@ include file="xdocserver.jsp" %>
 
<%
  String path = request.getContextPath();
  String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
  String xdocserver1 = EjbServerName.getValue("xdocserver");
  System.out.println("basePath basePath==========================="+basePath);
 %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
<% 
  StringBuffer sb=new StringBuffer();   
  String part = request.getParameter("szbm");
  String str1=new String(part.getBytes("ISO-8859-1"),"GBK");
  String sta = request.getParameter("syzt");
  String str2=new String(sta.getBytes("ISO-8859-1"),"GBK");
  String tems1 = "";
 if(str2.equals(" Is using ")){
   tems1="use";
  }else if(str2.equals(" Stop using ")){
   tems1="pause";
  }else if(str2.equals(" Stop using ")){
   tems1="stop";
  } else{
   tems1="use";
  }
  String s1 = Base64.encodeFixLenString(tems1);
  String sql="";
   List menuList=new ArrayList();   
   sql =" select t.companyid ,a.laborname ,t.keysn ,t.keystatus from sys_key t "+
   " left join IBSUSERS b on b.id = t.id left join labor a on a.labornum = b.labornum where 1=1 ";
   if(!str1.equals("")){
    sql +=" and t.companyid like '%"+str1+"%' ";
   }
   if(!s1.equals("")){
    sql +=" and t.keystatus = '"+s1+"'";
   }
    try {
    List list = IBOSrvUtil.getBaseDao().selectListBySql(sql);
    sb.append("<xdata>");
    if(list.size()>0){
     for(int i=0;i<list.size();i++){
      Map map = (Map) list.get(i);
      sb.append("<row>");       
      String keysn=Base64.decodeToFixLenString(map.get("KEYSN")==null?"":map.get("KEYSN").toString());
      String laborname=map.get("LABORNAME")==null?"":map.get("LABORNAME").toString();
      String companyid=map.get("COMPANYID")==null?"":map.get("COMPANYID").toString();
      String temstatus =Base64.decodeToFixLenString(map.get("KEYSTATUS")==null?"":map.get("KEYSTATUS").toString());      
      Map<String, String> compMap = new HashMap<String, String>();
       String status = "";
      if(temstatus.equals("use")){
       status=" Is using ";
      }else if(temstatus.equals("pause")){
       status=" Stop using ";
      }else{
       status=" Stop using ";
      }    
         sb.append("<col1>").append(keysn).append("</col1>");
         sb.append("<col2>").append(laborname).append("</col2>");
         sb.append("<col3>").append(companyid).append("</col3>");
         sb.append("<col4>").append(status).append("</col4>");
                
        sb.append("</row>");
    }
    }
    sb.append("</xdata>");
    } catch (Exception e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
    }
  System.out.println("sb===null=============="+sb);
 %> 
   <iframe name="xdoc" width="100%" height="100%"></iframe> 
  <form name="form1" action="http://11.1.1.152:8088/xdoc/realty/mycx.xdoc" method="post" target="xdoc" style="display: none">
  <input name="data" type="hidden" value="<%=sb.toString()%>" />
    
  </form>
</body>
 <script language="javascript">
   document.form1.submit();
  </script>   
  <script type="text/javascript"> 
   function dosubmit(){
     document.getElementById("btnSub").disabled = true;
     if(document.getElementById("szbm" ).value!="" || document.getElementById("syzt" ).value!="" )
     {
     var f1 = document.getElementById("b1");
     f1.submit();
     } else{
     alert(" Please enter query criteria! ");
     document.getElementById("btnSub").disabled = false;
     return ;
     }  
   }
   // If this 3 If all the conditions are empty, a prompt box will pop up. Otherwise do F1 And submit F1. That's what you get B1   
</html>

Hopefully, the sample code for this article has been helpful


Related articles: