jsp,div 限制字数,超出部分用省略号代替

1.我是用struts2标签做的:如下:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>博客列表</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/css/main.css">
	<script type="text/javascript">
		function goTo(maxPage){
			var currentPage = document.getElementById("text1").value;
			if(currentPage>maxPage || currentPage<1){
				alert("对不起,无法到达该页");
			}else{
				document.location.href="<%=request.getContextPath()%>/BlogAction_findAllBlog.action?pageNo="+currentPage;
			}
		}
	</script>
</head>
<body>
<div class="center_division">
	<div class="center_body">
		<table id="tb">
		<%--
		<tr>
			<td width="15%" bgcolor="#eef0f7">标题</td>
			<td bgcolor="#eef0f7">内容</td>
		</tr>
		--%>
		<s:iterator value="articleList" var="article">
		<tr>
			<td align="left" style="padding-left: 20px; font-size: 14px;">
				<a href="#"><s:property value="#request['articleTitle']"/></a>
			</td>
		</tr>
		<tr>
			<td>
			<s:if test="#request['articleContent'].length()>100">
				<s:property value="#request['articleContent'].substring(0,100)"/>......
			</s:if>
			<s:else>
				<s:property value="#request['articleContent']"/>......
			</s:else>
			</td>
		</tr>
		<tr>
			<td align="right" style="padding-right: 10px;">
			发布时间:<s:property value="#request['articleCreateDate']"/>
			<!-- 
			更新时间:<s:property value="#request['articleUpdateDate']"/>
			 -->
			</td>
		</tr>
		</s:iterator>
	</table>
	</div>
</div>
</body>
</html>


2.最后的效果截图如下:

jsp,div 限制字数,超出部分用省略号代替_第1张图片

你可能感兴趣的:(jsp)