springmvc+maven+sitemesh+bootstrap

来源:互联网 发布:中天制片软件 编辑:程序博客网 时间:2024/05/29 16:20

前面把spring mvc+maven+mybatis+logback全做完了,现在加上页面装饰的框架sitemesh+bootstrap

1、在maven的pom.xml加上sitemesh的依赖

 <dependency><groupId>opensymphony</groupId><artifactId>sitemesh</artifactId><version>2.4.2</version>  </dependency>
2、在web.xml中加上SiteMesh的过虑器,过虑器拦截的页面都会被sitemesh的母页装饰

<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>

3、在WEB-INF下加上:decorators.xml

<?xml version="1.0" encoding="UTF-8"?><decorators defaultdir="/WEB-INF/sitemesh/">//定义sitemesh的母页位置<decorator name="main" page="basic.jsp"><pattern>/*</pattern></decorator></decorators

4、在WEB-INF/sitemesh下加入basic.jsp,这个jsp用的是bootstrap的模板,先下载bootstrap模板,用一个自己喜欢的模板,改一下里面的东西,如菜单,header等等,重点是:page-content是由mvc返回的jsp填充

<%@ taglib prefix="decorator" uri="http://www.opensymphony.com/sitemesh/decorator"%> 

<div class="page-content-wrapper"><div class="page-content"><decorator:body/></div><!-- END PAGE CONTENT--></div></div>

基本上整个设置已经完成,可能遇到的问题:

1、自己在jsp里写的javascript代码找不到,解决方法:将srcipt的代码放到<body>体中

<body><script src="<%=request.getContextPath()%>/script/textArea.selection.js"></script><script type="text/javascript">var path="<%=request.getContextPath() %>";var pageSize = 100;

附上效果图:

1、没加sitemesh和bootstrap之前



2、加上sitemesh和bootstrap



1 0
原创粉丝点击