java 数据的加密与解密普遍实例代码
这是一个关于密钥查询的jsp文件,接受上级文件的数据并加密处理,放入Map集合中,通过form表单提交到xdoc文件中;不过这种做法是为了满足公司的要求,用到了框架的内容不免显得繁琐;下篇文章会介绍一种简便的不需要搭建太多环境的普遍做法。
<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("正在使用")){ tems1="use"; }else if(str2.equals("暂停使用")){ tems1="pause"; }else if(str2.equals("停止使用")){ 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="正在使用"; }else if(temstatus.equals("pause")){ status="暂停使用"; }else{ status="停止使用"; } 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("请输入查询条件!"); document.getElementById("btnSub").disabled = false; return ; } } //如果这三个条件同时为空的话就弹出提示框。否则执行F1并提交F1.就是得到的B1 </html>
希望本篇文章实例代码对您有所帮助
赞 (0)