用sitemesh装饰jsp页面,被装饰的jsp页面中用jsp:include包含另一个jsp页面,最终不能正常显示内容。
首先我将sitemesh2.4.2.jar包导入到项目的lib包中,之后编写我的装饰页面,页面很简单:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator" %>
<!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><decorator:title/></title>
</head>
<body>
<div>
<div><h1>小系统</h1></div>
<hr/>
</div>
<decorator:body/>
</body>
</html>
之后我写了一下decorators.xml,代码如下:
<?xml version="1.0" encoding="UTF-8"?>
<decorators defaultdir="/WEB-INF/decorators">
<!-- Any urls that are excluded will never be decorated by Sitemesh -->
<excludes>
<pattern>/exclude.jsp</pattern>
<pattern>/exclude/*</pattern>
</excludes>
<decorator name="main" page="decorator.jsp">
<pattern>/*</pattern>
</decorator>
</decorators>
然后配置web.xml,在web.xml中添加如下代码:
<filter>
<filter-name>sitemesh</filter-name>
<filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
好了,接着我写了一个servlet,通过这个servlet访问下面的list.jsp页面:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!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>用户列表界面</title>
</head>
<body>
<div><form action="user.do">
<input type="hidden" name="method" value="list"/>
<table align="center" border=1 cellpadding="0" cellspacing="0" width="800">
<tr><td colspan="6">请输入要查询的用户名:<input type="text" name="search" /><input type="submit" value="查询"/></td></tr>
<tr><td>id</td><td>用户名</td><td>用户密码</td><td>用户昵称</td><td>用户类型</td><td>操作</td></tr>
<c:forEach var="user" items="${page.list }">
<tr><td>${user.id }</td><td>${user.username }</td><td>${user.password }</td><td>${user.nickname }</td>
<td>
<c:choose>
<c:when test="${user.type ne true }">超级无敌管理员</c:when>
<c:otherwise>普通屌丝</c:otherwise>
</c:choose>
</td>
<td><a href="">修改信息</a> <a href="">删除</a></td></tr>
</c:forEach>
<tr><td colspan="6">
<jsp:include page="/inc/pager.jsp">
<jsp:param value="${page.totalNum }" name="totalNum"/>
<jsp:param value="${page.dataCount }" name="dataCount"/>
<jsp:param value="/shop01/user.do" name="url"/>
<jsp:param value="method,search" name="params"/>
</jsp:include>
</td></tr>
</table>
</form></div>
</body>
</html>
可是访问结果却是:
后来我把上面的list.jsp中的jsp:include标签中的内容注释掉,列表就能正常显示。后来我重新建立项目试了几次,发现只要被sitemesh装饰的页面中含有jsp:include内容,就只能显示jsp:include动态包含的内容和装饰页面的内容。
这是怎么一回事?被装饰页面中原有的内容为什么在有了动态包含之后就不能显示了?求大神解答~~~~