jsp页面字符串截取,点击弹出弹出层

无情 2013-08-20

1、jsp页面

<!--弹出层js-->
<script type="text/javascript" src="mainpage/js/jquery_dialog.js"></script>
<link rel="stylesheet" type="text/css" href="mainpage/css/jquery_dialog.css" />
<!--base64编码解码-->
<script type="text/javascript" src="${path}/js/Base64-80.js"></script>
<!--截取字符串-->
<script type="text/javascript" src="${path}/js/dealstring.js"></script>




<td title="<s:property value='#vl.virusFileName'/>">
    <script type="text/javascript">document.write(dealLn("${vl.virusFileName}",24))</script>
</td>

2、dealstring.js

/**
 * 字符串带有换行符且长度大于25时 进行处理
 * @param text
 * @return
 */
function dealLn(text,length){
	var strlen = 0;
	var s = "";
	var str = text;
	if(null !=text && text.length>0){
		for ( var i = 0; i < text.length; i++) {
			//一个汉字2个字符
			if (text.charCodeAt(i) > 128) {
				strlen += 2;
			} else {
				strlen++;
			}
			s += text.charAt(i);
			if (strlen >= length) {
				text = s + "...";
				break;
			}
		}
	}
	
	if(null != str && '' != str && "" != str){
		str = encode64(str);
	}
	//encodeURI(encodeURI(str))
	text = "<a style='text-decoration:none;color: black;' onclick=\"JqueryDialog.Open1('详情', '/common/logshow.jsp?message="+str+"',370, 120)\" >"+text+"</a>";
	return text;
}

3、Base64-80.js,base64编码

见附件

4、logshow.jsp,弹出层的jsp页面

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <title>My JSP 'showLog.jsp' starting page</title>
	<meta http-equiv="pragma" content="no-cache">
	<script language="javascript" type="text/javascript">
		$(function(){
		//decode64(decodeURI(decodeURI('')));
			var ds =  '<%=request.getParameter("message")%>';
          	if(ds!='null' && ds!=null && ''!=ds){
          	ds = ds.split(" ").join("+");
          	ds = decode64(ds);
          		$("#detls").val(ds);
          		$("#detls").css("display","block");
          	}else{
          		$("#detls").css("display","none"); 
          	}
		
		});
          
     </script>
  </head>
  <body>
     
      
     
      <textarea id="detls" rows='8' cols='17' 
				style='width: 350px; height: 100px;display: none;margin-left: 10px;'></textarea>
     
   
  </body>
</html>

相关推荐