JAVA循环数组输出HTML代码片段并对字符串进行base64编码
		
		
		[
 2015/10/27 13:04 | by 刘新修 ]
		
	
 2015/10/27 13:04 | by 刘新修 ]
		Java代码
- <%@page trimDirectiveWhitespaces="true"%>
 - <%@page language="java" pageEncoding="utf-8"%>
 - <%@page import="sun.misc.*"%>
 - <%@page import="java.io.*"%>
 - <%@page import="java.util.*"%>
 - <%
 - List<String> htmltempList=new ArrayList<String>();
 - //String[][] students = {{'小明','1101','23','52819911'},{'夏利','1101','23','52819911'},{'小强','1102','21','52819901'}};
 - //创建6行4列二位数组
 - String[][] book=new String [6][4];
 - book[0]=new String[]{"风清扬","1101","23","52819911"};
 - book[1]=new String[]{"许志飞","1101","23","52819911"};
 - book[2]=new String[]{"令狐冲","1102","21","52819901"};
 - book[3]=new String[]{"任我行","1103","22","52819991"};
 - book[4]=new String[]{"任盈盈","1104","24","52819981"};
 - book[5]=new String[]{"东方不败","1105","26","52819981"};
 - String[][] arr1={{"11","22"},{"aaa","bbb"},{"AAA","BBB"}};
 - String[][] arr2=new String[3][2];
 - for(int i=0;i<book.length;i++){
 - htmltempList.add("<ul>");
 - for(int j=0;j<book[i].length;j++){
 - //out.println(book[i][j]);
 - htmltempList.add("<li>" +book[i][j]+"</li>");
 - }
 - htmltempList.add("</ul>");
 - }
 - /*
 - int [][]a=new int[8][8];
 - for (int i=0;i<8;i++){
 - for(int j=0;j<8;j++){
 - a[i][j]=i+j;
 - out.println(a[i][j]+"---");
 - }
 - }*/
 - //out.println("---");
 - %>
 - <%
 - for (int i=0;i<9;i++){
 - //htmltempList.add("<li><span>" + i+"</span></li>");
 - }
 - /*
 - for (int i=0; i<htmltempList.size();i++){
 - out.print(htmltempList.get(i));
 - }
 - out.print(testCol(htmltempList) + "====================");
 - */
 - %>
 - <%
 - response.setContentType("text/json");
 - response.setCharacterEncoding("utf-8");
 - String callback=request.getParameter("Jsoncallback");
 - if(callback!=null&&!"".equals(callback)){
 - out.print(callback+"({\"dataList\":\"" +testColCon(htmltempList) + "\"})");
 - }
 - %>
 - <%!
 - public static int testCol(List<String> testList){
 - return testList.size();
 - }
 - public static String testColCon(List<String> testList){
 - String str="";
 - String html="<style>*{margin:0;padding:0;}h1{font-size:16px;text-align:center; line-height:45px;}body{color:#333;font-size:14px;font-family:'MicrosoftYahei';background:#B7CACC;}div{border:1px solid #405E7B; border-bottom:0; width:95%; margin:0 auto;background:#fff;content:'';display:table;clear:both}li{line-height:35px;list-style:none;width:25%;text-align:center;border-bottom:1px solid #405E7B;float:left;}</style><h1>最近风云人员名单</h1><div>";
 - for (int i=0; i<testList.size();i++){
 - str+=testList.get(i);
 - }
 - html+=str;
 - byte[] b=null;
 - String s=null;
 - try{
 - b=html.getBytes("utf-8");
 - }catch(UnsupportedEncodingException e){
 - e.printStackTrace();
 - }
 - if (b!=null){
 - s=new BASE64Encoder().encode(b);
 - s=s.replaceAll("\r\n","");
 - s=s.replaceAll("\n","");
 - // s = s.replaceAll("","");
 - //s="PGxpPjxzcGFuPjA8L3NwYW4+PC9saT48bGk+PHNwYW4+MTwvc3Bhbj48L2xpPjxsaT48c3Bhbj4yPC9zcGFuPjwvbGk+PGxpPjxzcGFuPjM8L3NwYW4+PC9saT48bGk+PHNwYW4+NDwvc3Bhbj48L2xpPjxsaT48c3Bhbj41PC9zcGFuPjwvbGk+PGxpPjxzcGFuPjY8L3NwYW4+PC9saT48bGk+PHNwYW4+Nzwvc3Bhbj48L2xpPjxsaT48c3Bhbj44PC9zcGFuPjwvbGk+";
 - }
 - return s;
 - }
 - %>
 


  
 
 
 
 
 


