- 浏览: 269492 次
- 性别:
- 来自: 新乡
文章分类
- 全部博客 (227)
- servciemix (10)
- db (18)
- javaTools (4)
- hibernate (31)
- web (3)
- spring (14)
- design pattern (4)
- java security (3)
- portal (1)
- ejb (6)
- session (2)
- java_lang (21)
- jbpm (29)
- struts (7)
- orgRights (2)
- project manager Jira (7)
- 跨库事务 (2)
- mysql (14)
- ubuntu (7)
- osgi (9)
- maven ant make (4)
- 分布式 高并发 高性能 (5)
- virgo-dm_server (0)
- osgi web (3)
- platform (1)
- smooks (1)
- business (1)
- 职场生涯 (14)
- Java编码格式 (2)
- web服务 (1)
- 计算机使用 (1)
- 健康工作生活的保障,工作中务必抛掉的不良心态 (4)
- 电信-网络监控 (1)
- 多线程-multithread (1)
- 海量数据-高性能 (2)
- Mybatis (1)
- web开发平台研发 (0)
- oracle (0)
- 应用服务器调优 (0)
- web前端 (0)
- servlet-jsp (0)
- tomcat (2)
- newtouch (1)
- portal_liferay (2)
- version control (1)
- apm-impact (2)
- tools (1)
- 研发管理 (1)
- 电商业务 (1)
- 生鲜电商市场调查 (0)
- PBX (0)
- 房东 (0)
最新评论
-
lifuchao:
...
权限问题 -
Branding:
谢谢,受教了,另外,CONN AS SYSDBA,必须是在操作 ...
Oracle密码忘记了怎么办? -
zhuchao_ko:
...
Portal实现原理 -
败类斯文:
不知道改哪里。。。木有见到红色。。表示悟性低了、、
jira error: Neither the JAVA_HOME nor the JRE_HOME environment variable is defin -
c__06:
正文:假如事务我是这样定义的: <tx:method n ...
Spring中Transactional配置
整合struts2.1.8.1+sitemesh2.4.2+freemarker2.3.15+spring2.5+hibernate3.3.1
博客分类:
系统架构
JSPServletStrutsCSSfreemarker
由struts2.1.6升级,整合struts2.1.8.1+sitemesh2.4.2+freemarker2.3.15+spring2.5+hibernate3.3.1
由于struts2.1.8.1 sitemesh和freemarker的配置方式改变了,查遍了官方文档和百度 google都没有找到解决问题的办法,自己尝试了N种方法后才找到解决办法,在此分享下。
web.xml
Xml代码 收藏代码
<?xml version="1.0" encoding="utf-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>iemis base system</display-name>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:log4j.properties</param-value>
</context-param>
<filter>
<filter-name>SetCharacterEncoding</filter-name>
<filter-class>com.iemis.base.util.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>ignore</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter>
<filter-name>encoding</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter>
<filter-name>openSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<strong><filter>
<filter-name>struts-prepare</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareFilter</filter-class>
</filter>
<filter>
<filter-name>sitemesh</filter-name>
<filter-class>org.apache.struts2.sitemesh.FreeMarkerPageFilter</filter-class>
</filter>
<filter>
<filter-name>struts-execute</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsExecuteFilter</filter-class>
</filter></strong>
<!--
<filter>
<filter-name>struts-cleanup</filter-name>
<filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
</filter>
<filter>
<filter-name>sitemesh</filter-name>
<filter-class>org.apache.struts2.sitemesh.FreeMarkerPageFilter</filter-class>
</filter>
<filter>
<filter-name>struts</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
-->
<filter-mapping>
<filter-name>SetCharacterEncoding</filter-name>
<servlet-name>action</servlet-name>
</filter-mapping>
<filter-mapping>
<filter-name>openSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts-prepare</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts-execute</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!--
<filter-mapping>
<filter-name>struts-cleanup</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
-->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>jspSupportServlet</servlet-name>
<servlet-class>org.apache.struts2.views.JspSupportServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>sitemesh-freemarker</servlet-name>
<servlet-class>com.opensymphony.module.sitemesh.freemarker.FreemarkerDecoratorServlet</servlet-class>
<init-param>
<param-name>TemplatePath</param-name>
<param-value>/</param-value>
</init-param>
<init-param>
<param-name>default_encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<strong><servlet-mapping>
<servlet-name>sitemesh-freemarker</servlet-name>
<url-pattern>*.action</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>sitemesh-freemarker</servlet-name>
<url-pattern>*.ftl</url-pattern>
</servlet-mapping></strong>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<error-page>
<error-code>403</error-code>
<location>/error403.jsp</location>
</error-page>
<!-- error-page>
<error-code>404</error-code>
<location>/error.jsp</location>
</error-page>
<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/error.jsp</location>
</error-page-->
</web-app>
注意:sitemesh-freemarker这个servlet要同时匹配action和ftl两个才可以,不能用/*匹配所有的,否则图片样式等也会给装饰。官方文档的访问后缀名就是.ftl不是action,但只配置了action ftl文件他就无法解析了,必须两个都配置了才行。
struts和sitemesh的配置也要用新的方式,否则freemarker里面action变量不能使用。
decorators.xml
Xml代码 收藏代码
<?xml version="1.0" encoding="UTF-8"?>
<!--
定义构成复合视图的所有页面构件的描述
(主要结构页面,header,footer...),如下例:
-->
<decorators defaultdir="/decorators">
<!-- 在excludes元素下指定的页面将不会由SiteMesh来装饰 -->
<excludes>
<pattern>/index.jsp</pattern>
<pattern>/scripts/*.*</pattern>
<pattern>/images/*.*</pattern>
<pattern>/styles/*.*</pattern>
<pattern>/jasperreport/*.*</pattern>
</excludes>
<!-- iframe里面内容页面装饰器 -->
<decorator name="simple" page="simple.ftl">
<pattern>/browser/*/*/*.action</pattern>
<pattern>/editor/*/*/*.action</pattern>
<pattern>/admin/*/*/*.action</pattern>
<pattern>/browser/home/*.action</pattern>
<pattern>/editor/home/*.action</pattern>
<pattern>/admin/*/*.action</pattern>
<pattern>*.action</pattern>
</decorator>
<decorator name="complete" page="complete.ftl" webapp="/browser/">
<pattern>/browser/*.action</pattern>
<pattern>/editor/*.action</pattern>
<pattern>/admin/*.action</pattern>
</decorator>
</decorators>
<!--
<decorator name="blog_editor" page="blog.ftl" webapp="/editor/">
<pattern>/editor/*.action</pattern>
</decorator>
<decorator name="blog_browser" page="blog.ftl" webapp="/browser/">
<pattern>/browser/*.action</pattern>
<pattern>/login.action</pattern>
</decorator>
<decorator name="admin" page="admin.ftl" webapp="/admin/">
<pattern>/admin/*.action</pattern>
</decorator>
-->
<!--
<decorator name="panel" page="panel.jsp" />
<decorator name="printable" page="printable.jsp" />
<decorator name="printable" page="printable.jsp" role="customer"
webapp="aaa" />
-->
<!--
<decorator name="footer" page="headerfooter.jsp">
<pattern>/index.jsp</pattern>
</decorator>
-->
<!--
其实,重要的工作就是制作装饰器页面本身(也就是包含结构和规则的页面),
然后把他们描述到decorators.xml中。
-->
<!--
defaultdir: 包含装饰器页面的目录
page : 页面文件名
name : 别名
role : 角色,用于安全
webapp : 可以另外指定此文件存放目录
Patterns : 匹配的路径,可以用*,那些被访问的页面需要被装饰。
-->
struts.xml
Xml代码 收藏代码
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN"
"http://struts.apache.org/dtds/struts-2.1.dtd">
<constant name="struts.custom.i18n.resources" value="message"/>
<!-- 当struts配置文件修改后,系统是否重新加载配文件,默认是false -->
<constant name="struts.configuration.xml.reload" value="true" />
<struts>
<package name="default" extends="struts-default">
<global-results>
<result name="error" type="freemarker">/common/action_error.ftl</result>
</global-results>
<action name="login" class="com.iemis.base.action.LoginAction">
<result name="input" type="freemarker">/common/login.ftl</result>
<result name="success" type="redirect">/index.jsp</result>
</action>
</package>
<!-- browser -->
<package name="browser" extends="struts-default" namespace="/browser">
<global-results>
<result name="error" type="freemarker">/common/action_error.ftl</result>
<result name="input" type="freemarker">/common/action_blank.ftl</result>
<result name="success" type="freemarker">/common/action_success.ftl</result>
</global-results>
<action name="home" class="com.iemis.base.action.BaseAction" method="complete">
<result name="success" type="freemarker">home.ftl</result>
</action>
</package>
<package name="browser_home" extends="struts-default" namespace="/browser/home">
<global-results>
<result name="error" type="freemarker">/common/action_error.ftl</result>
<result name="input" type="freemarker">/common/action_blank.ftl</result>
<result name="success" type="freemarker">/common/action_success.ftl</result>
</global-results>
<action name="show" class="com.iemis.base.action.BaseAction" method="show">
<result name="success" type="freemarker">show.ftl</result>
</action>
</package>
</struts>
complete.ftl
Html代码 收藏代码
<#assign page=JspTaglibs["/WEB-INF/tld/sitemesh-page.tld"]>
<#include "/common/util.ftl">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><@getText "page.title"/>--${title}</title>
<link href="${base}/styles/util.css" type="text/css" rel="stylesheet" />
<link href="${base}/styles/default.css" type="text/css" rel="stylesheet" />
<link href="${base}/styles/complete.css" type="text/css" rel="stylesheet" />
<link href="${base}/styles/coos/menu.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="${base}/scripts/coos.js"></script>
<script type="text/javascript" src="${base}/scripts/coos.iemis.js"></script>
<script type="text/javascript" src="${base}/scripts/coos.ui.menu.js"></script>
<script type="text/javascript" src="${base}/scripts/coos.ui.dialogbox.js"></script>
${head}
</head>
<body>
<div id="page">
<#include "/common/head.ftl">
<#if actionErrors?size == 0>
<div id="headNav">
</div>
<script type="text/javascript">
coos.onloadEvent(function(){
//创建一个对象
var menu = new coosmenu("headNav");
<#list baseMenus as menu>
<#assign url><#t>
<#if menu.url?exists>${base}${menu.url}<#else>#this</#if><#t>
</#assign>
<#assign isVisiable><#t>
<#if menu.isVisiable==0>true<#else>false</#if><#t>
</#assign>
<#if !(menu.codeno?exists && ((!editor && menu.codeno=="userManage") || (!admin && menu.codeno=="systemconfig")))>
menu.add(${menu.id},${menu.pid},'${menu.name}','${url}','${menu.title?default("null")}','${menu.target?default("null")}','${menu.isLast?default("null")}','${menu.icon?default("null")}','${menu.iconopen?default("null")}',${isVisiable});
</#if>
</#list>
});
</script>
${body}
<#else>
<div class="page_width">
${body}
</div>
</#if>
<#include "/common/footer.ftl">
</div>
</body>
</html>
simple.ftl
Html代码 收藏代码
<#assign page=JspTaglibs["/WEB-INF/tld/sitemesh-page.tld"]>
<#include "/common/util.ftl">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>${title}</title>
<link href="${base}/styles/util.css" type="text/css" rel="stylesheet" />
<link href="${base}/styles/default.css" type="text/css" rel="stylesheet" />
<link href="${base}/styles/simple.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="${base}/scripts/coos.js"></script>
<script type="text/javascript" src="${base}/scripts/coos.iemis.js"></script>
${head}
</head>
<body>
<#if actionErrors?size == 0>
<#include "/common/action_message.ftl">
${body}
<#else>
${body}
</#if>
</body>
</html>
browser/home.ftl
Html代码 收藏代码
<#include "/common/util.ftl">
<#assign title><@getText "page.title"/><@getText "page.home"/></#assign>
<html>
<head>
<title>${title}</title>
</head>
<body>
<@box title "box_width">
<@iframe "browser_home" "${base}/browser/home/show.action" />
</@box>
</body>
</html>
browser/home/show.ftl
Html代码 收藏代码
<#include "/common/util.ftl">
<html>
<head>
<title><@getText "page.home"/></title>
</head>
<body>
<br /><br /><br /><br />
<div class="success">
${baseConfs["welcome"]?default("welcome")}
</div>
</body>
</html>
applicationContext.xml
Xml代码 收藏代码
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<context:property-placeholder location="classpath:application.properties" />
<import resource="classpath:application-dao.xml"/>
<import resource="classpath:application-service.xml"/>
<import resource="classpath:application-security.xml"/>
</beans>
注意:sitemesh-freemarker这个servlet要同时匹配action和ftl两个才可以,不能用/*匹配所有的,否则图片样式等也会给装饰。官方文档的访问后缀名就是.ftl不是action,但只配置了action ftl文件他就无法解析了,必须两个都配置了才行。如果你的模版不是以ftl为后缀的要改成对应的后缀,如.html .dec要改成对应的。
Xml代码 收藏代码
<servlet>
<servlet-name>sitemesh-freemarker</servlet-name>
<servlet-class>com.opensymphony.module.sitemesh.freemarker.FreemarkerDecoratorServlet</servlet-class>
<init-param>
<param-name>TemplatePath</param-name>
<param-value>/</param-value>
</init-param>
<init-param>
<param-name>default_encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>sitemesh-freemarker</servlet-name>
<url-pattern>*.action</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>sitemesh-freemarker</servlet-name>
<url-pattern>*.ftl</url-pattern>
</servlet-mapping>
struts和sitemesh的配置也要用新的方式,否则freemarker里面action变量不能使用。
Xml代码 收藏代码
<filter>
<filter-name>struts-prepare</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareFilter</filter-class>
</filter>
<filter>
<filter-name>sitemesh</filter-name>
<filter-class>org.apache.struts2.sitemesh.FreeMarkerPageFilter</filter-class>
</filter>
<filter>
<filter-name>struts-execute</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts-prepare</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts-execute</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
spring2.5和hibernate3.3.1的配置和以前版本一致,除了更新插件包不需要改动其他的东西。
博客分类:
系统架构
JSPServletStrutsCSSfreemarker
由struts2.1.6升级,整合struts2.1.8.1+sitemesh2.4.2+freemarker2.3.15+spring2.5+hibernate3.3.1
由于struts2.1.8.1 sitemesh和freemarker的配置方式改变了,查遍了官方文档和百度 google都没有找到解决问题的办法,自己尝试了N种方法后才找到解决办法,在此分享下。
web.xml
Xml代码 收藏代码
<?xml version="1.0" encoding="utf-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>iemis base system</display-name>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:log4j.properties</param-value>
</context-param>
<filter>
<filter-name>SetCharacterEncoding</filter-name>
<filter-class>com.iemis.base.util.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>ignore</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter>
<filter-name>encoding</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter>
<filter-name>openSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<strong><filter>
<filter-name>struts-prepare</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareFilter</filter-class>
</filter>
<filter>
<filter-name>sitemesh</filter-name>
<filter-class>org.apache.struts2.sitemesh.FreeMarkerPageFilter</filter-class>
</filter>
<filter>
<filter-name>struts-execute</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsExecuteFilter</filter-class>
</filter></strong>
<!--
<filter>
<filter-name>struts-cleanup</filter-name>
<filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
</filter>
<filter>
<filter-name>sitemesh</filter-name>
<filter-class>org.apache.struts2.sitemesh.FreeMarkerPageFilter</filter-class>
</filter>
<filter>
<filter-name>struts</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
-->
<filter-mapping>
<filter-name>SetCharacterEncoding</filter-name>
<servlet-name>action</servlet-name>
</filter-mapping>
<filter-mapping>
<filter-name>openSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts-prepare</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts-execute</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!--
<filter-mapping>
<filter-name>struts-cleanup</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
-->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>jspSupportServlet</servlet-name>
<servlet-class>org.apache.struts2.views.JspSupportServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>sitemesh-freemarker</servlet-name>
<servlet-class>com.opensymphony.module.sitemesh.freemarker.FreemarkerDecoratorServlet</servlet-class>
<init-param>
<param-name>TemplatePath</param-name>
<param-value>/</param-value>
</init-param>
<init-param>
<param-name>default_encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<strong><servlet-mapping>
<servlet-name>sitemesh-freemarker</servlet-name>
<url-pattern>*.action</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>sitemesh-freemarker</servlet-name>
<url-pattern>*.ftl</url-pattern>
</servlet-mapping></strong>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<error-page>
<error-code>403</error-code>
<location>/error403.jsp</location>
</error-page>
<!-- error-page>
<error-code>404</error-code>
<location>/error.jsp</location>
</error-page>
<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/error.jsp</location>
</error-page-->
</web-app>
注意:sitemesh-freemarker这个servlet要同时匹配action和ftl两个才可以,不能用/*匹配所有的,否则图片样式等也会给装饰。官方文档的访问后缀名就是.ftl不是action,但只配置了action ftl文件他就无法解析了,必须两个都配置了才行。
struts和sitemesh的配置也要用新的方式,否则freemarker里面action变量不能使用。
decorators.xml
Xml代码 收藏代码
<?xml version="1.0" encoding="UTF-8"?>
<!--
定义构成复合视图的所有页面构件的描述
(主要结构页面,header,footer...),如下例:
-->
<decorators defaultdir="/decorators">
<!-- 在excludes元素下指定的页面将不会由SiteMesh来装饰 -->
<excludes>
<pattern>/index.jsp</pattern>
<pattern>/scripts/*.*</pattern>
<pattern>/images/*.*</pattern>
<pattern>/styles/*.*</pattern>
<pattern>/jasperreport/*.*</pattern>
</excludes>
<!-- iframe里面内容页面装饰器 -->
<decorator name="simple" page="simple.ftl">
<pattern>/browser/*/*/*.action</pattern>
<pattern>/editor/*/*/*.action</pattern>
<pattern>/admin/*/*/*.action</pattern>
<pattern>/browser/home/*.action</pattern>
<pattern>/editor/home/*.action</pattern>
<pattern>/admin/*/*.action</pattern>
<pattern>*.action</pattern>
</decorator>
<decorator name="complete" page="complete.ftl" webapp="/browser/">
<pattern>/browser/*.action</pattern>
<pattern>/editor/*.action</pattern>
<pattern>/admin/*.action</pattern>
</decorator>
</decorators>
<!--
<decorator name="blog_editor" page="blog.ftl" webapp="/editor/">
<pattern>/editor/*.action</pattern>
</decorator>
<decorator name="blog_browser" page="blog.ftl" webapp="/browser/">
<pattern>/browser/*.action</pattern>
<pattern>/login.action</pattern>
</decorator>
<decorator name="admin" page="admin.ftl" webapp="/admin/">
<pattern>/admin/*.action</pattern>
</decorator>
-->
<!--
<decorator name="panel" page="panel.jsp" />
<decorator name="printable" page="printable.jsp" />
<decorator name="printable" page="printable.jsp" role="customer"
webapp="aaa" />
-->
<!--
<decorator name="footer" page="headerfooter.jsp">
<pattern>/index.jsp</pattern>
</decorator>
-->
<!--
其实,重要的工作就是制作装饰器页面本身(也就是包含结构和规则的页面),
然后把他们描述到decorators.xml中。
-->
<!--
defaultdir: 包含装饰器页面的目录
page : 页面文件名
name : 别名
role : 角色,用于安全
webapp : 可以另外指定此文件存放目录
Patterns : 匹配的路径,可以用*,那些被访问的页面需要被装饰。
-->
struts.xml
Xml代码 收藏代码
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN"
"http://struts.apache.org/dtds/struts-2.1.dtd">
<constant name="struts.custom.i18n.resources" value="message"/>
<!-- 当struts配置文件修改后,系统是否重新加载配文件,默认是false -->
<constant name="struts.configuration.xml.reload" value="true" />
<struts>
<package name="default" extends="struts-default">
<global-results>
<result name="error" type="freemarker">/common/action_error.ftl</result>
</global-results>
<action name="login" class="com.iemis.base.action.LoginAction">
<result name="input" type="freemarker">/common/login.ftl</result>
<result name="success" type="redirect">/index.jsp</result>
</action>
</package>
<!-- browser -->
<package name="browser" extends="struts-default" namespace="/browser">
<global-results>
<result name="error" type="freemarker">/common/action_error.ftl</result>
<result name="input" type="freemarker">/common/action_blank.ftl</result>
<result name="success" type="freemarker">/common/action_success.ftl</result>
</global-results>
<action name="home" class="com.iemis.base.action.BaseAction" method="complete">
<result name="success" type="freemarker">home.ftl</result>
</action>
</package>
<package name="browser_home" extends="struts-default" namespace="/browser/home">
<global-results>
<result name="error" type="freemarker">/common/action_error.ftl</result>
<result name="input" type="freemarker">/common/action_blank.ftl</result>
<result name="success" type="freemarker">/common/action_success.ftl</result>
</global-results>
<action name="show" class="com.iemis.base.action.BaseAction" method="show">
<result name="success" type="freemarker">show.ftl</result>
</action>
</package>
</struts>
complete.ftl
Html代码 收藏代码
<#assign page=JspTaglibs["/WEB-INF/tld/sitemesh-page.tld"]>
<#include "/common/util.ftl">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><@getText "page.title"/>--${title}</title>
<link href="${base}/styles/util.css" type="text/css" rel="stylesheet" />
<link href="${base}/styles/default.css" type="text/css" rel="stylesheet" />
<link href="${base}/styles/complete.css" type="text/css" rel="stylesheet" />
<link href="${base}/styles/coos/menu.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="${base}/scripts/coos.js"></script>
<script type="text/javascript" src="${base}/scripts/coos.iemis.js"></script>
<script type="text/javascript" src="${base}/scripts/coos.ui.menu.js"></script>
<script type="text/javascript" src="${base}/scripts/coos.ui.dialogbox.js"></script>
${head}
</head>
<body>
<div id="page">
<#include "/common/head.ftl">
<#if actionErrors?size == 0>
<div id="headNav">
</div>
<script type="text/javascript">
coos.onloadEvent(function(){
//创建一个对象
var menu = new coosmenu("headNav");
<#list baseMenus as menu>
<#assign url><#t>
<#if menu.url?exists>${base}${menu.url}<#else>#this</#if><#t>
</#assign>
<#assign isVisiable><#t>
<#if menu.isVisiable==0>true<#else>false</#if><#t>
</#assign>
<#if !(menu.codeno?exists && ((!editor && menu.codeno=="userManage") || (!admin && menu.codeno=="systemconfig")))>
menu.add(${menu.id},${menu.pid},'${menu.name}','${url}','${menu.title?default("null")}','${menu.target?default("null")}','${menu.isLast?default("null")}','${menu.icon?default("null")}','${menu.iconopen?default("null")}',${isVisiable});
</#if>
</#list>
});
</script>
${body}
<#else>
<div class="page_width">
${body}
</div>
</#if>
<#include "/common/footer.ftl">
</div>
</body>
</html>
simple.ftl
Html代码 收藏代码
<#assign page=JspTaglibs["/WEB-INF/tld/sitemesh-page.tld"]>
<#include "/common/util.ftl">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>${title}</title>
<link href="${base}/styles/util.css" type="text/css" rel="stylesheet" />
<link href="${base}/styles/default.css" type="text/css" rel="stylesheet" />
<link href="${base}/styles/simple.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="${base}/scripts/coos.js"></script>
<script type="text/javascript" src="${base}/scripts/coos.iemis.js"></script>
${head}
</head>
<body>
<#if actionErrors?size == 0>
<#include "/common/action_message.ftl">
${body}
<#else>
${body}
</#if>
</body>
</html>
browser/home.ftl
Html代码 收藏代码
<#include "/common/util.ftl">
<#assign title><@getText "page.title"/><@getText "page.home"/></#assign>
<html>
<head>
<title>${title}</title>
</head>
<body>
<@box title "box_width">
<@iframe "browser_home" "${base}/browser/home/show.action" />
</@box>
</body>
</html>
browser/home/show.ftl
Html代码 收藏代码
<#include "/common/util.ftl">
<html>
<head>
<title><@getText "page.home"/></title>
</head>
<body>
<br /><br /><br /><br />
<div class="success">
${baseConfs["welcome"]?default("welcome")}
</div>
</body>
</html>
applicationContext.xml
Xml代码 收藏代码
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<context:property-placeholder location="classpath:application.properties" />
<import resource="classpath:application-dao.xml"/>
<import resource="classpath:application-service.xml"/>
<import resource="classpath:application-security.xml"/>
</beans>
注意:sitemesh-freemarker这个servlet要同时匹配action和ftl两个才可以,不能用/*匹配所有的,否则图片样式等也会给装饰。官方文档的访问后缀名就是.ftl不是action,但只配置了action ftl文件他就无法解析了,必须两个都配置了才行。如果你的模版不是以ftl为后缀的要改成对应的后缀,如.html .dec要改成对应的。
Xml代码 收藏代码
<servlet>
<servlet-name>sitemesh-freemarker</servlet-name>
<servlet-class>com.opensymphony.module.sitemesh.freemarker.FreemarkerDecoratorServlet</servlet-class>
<init-param>
<param-name>TemplatePath</param-name>
<param-value>/</param-value>
</init-param>
<init-param>
<param-name>default_encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>sitemesh-freemarker</servlet-name>
<url-pattern>*.action</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>sitemesh-freemarker</servlet-name>
<url-pattern>*.ftl</url-pattern>
</servlet-mapping>
struts和sitemesh的配置也要用新的方式,否则freemarker里面action变量不能使用。
Xml代码 收藏代码
<filter>
<filter-name>struts-prepare</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareFilter</filter-class>
</filter>
<filter>
<filter-name>sitemesh</filter-name>
<filter-class>org.apache.struts2.sitemesh.FreeMarkerPageFilter</filter-class>
</filter>
<filter>
<filter-name>struts-execute</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts-prepare</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts-execute</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
spring2.5和hibernate3.3.1的配置和以前版本一致,除了更新插件包不需要改动其他的东西。
发表评论
-
Struts2执行流程
2011-07-12 19:48 965Struts2执行流程 1. web.xml 部署描述符 2 ... -
struts-menu (权限动态菜单实现)(转)
2011-07-12 19:47 1231struts-menu (权限动态菜单实现)(转) pack ... -
Struts2文件的上传和下载
2011-07-12 16:59 650Struts2文件的上传和下载 ... -
Struts2源码分析--请求处理
2011-07-12 16:56 1115Struts2源码分析--请求处理 Posted on 200 ... -
JAVA WEB项目(struts1.X)乱码总结
2011-07-12 16:52 823JAVA WEB项目(struts1.X)乱码 ... -
about struts.devMode
2011-06-23 16:56 11301. ognl.OgnlException: target i ...
相关推荐
Apache Struts Copyright 2000-2007 The Apache Software Foundation This product includes software developed by The Apache Software Foundation (http://www.apache.org/). Dojo (http://dojotoolkit.org/). ...
struts2-sitemesh-plugin-2.1.8.1.jar
Struts2、Spring2.5 和 SiteMesh 是Java Web开发中的三个重要框架,它们共同构建了一个强大且灵活的Web应用程序架构。在这个小DEMO中,我们将深入探讨这三个框架的集成和工作原理。 **Struts2** 是一个基于MVC...
Struts2+Spring+Hibernate+sitemesh做的一个在线音乐站点写的一个在线音乐 的站点.功能实现的相对比较粗糙(如歌曲列表没考虑分页什么的),另外只能使用IE(使用了ActiveX 控件播放音乐的).
在《开发者突击:Java Web主流框架整合开发(J2EE+Struts+Hibernate+Spring)》架构讲解的过程中,穿插介绍了JDBC、Log4j、Sitemesh、JUnit技术。 随书附赠光盘内容包括《开发者突击:Java Web主流框架整合开发(J2EE+...
MyEclipse8.0中自带的struts2版本是2.1.6,spring版本有2.0,2.5的,hibernate版本较多些至3.2,首先选版本就选择最优的,struts2没的选只有2.1.6版的,所以先导入struts2支持,然后是spring选的是2.0,问题就出在...
【标题】基于Shiro+Struts2+Hibernate+Spring+Sitemash框架集合的毕业设计管理系统是一种综合运用多种技术实现的企业级应用。这个系统利用这些框架的特性,构建了一个功能完善的管理平台,旨在提升开发效率,优化...
它们各自承担着不同的职责,并且在实际项目中经常被整合使用,形成了所谓的"SSH2"(Struts2 + Spring + Hibernate)框架组合,加上JPA和SiteMesh,进一步提升了开发效率和应用的可维护性。 1. **Struts2**:这是一...
【Struts2+Spring+Hibernate 整合应用】 在Java Web开发中,Struts2、Spring和Hibernate是三个非常重要的开源框架。它们各自解决了不同层面的问题,而将它们整合在一起可以构建出高效、灵活和可维护的Web应用程序。...
Struts2、Spring2、Hibernate3、Velocity和Sitemesh是经典的Java Web开发框架组合,它们各自在Web应用的不同层面提供了强大的支持。这个集成框架代码集合了这些技术,旨在提供一个高效、灵活和可扩展的开发环境。 1...
Struts2、Spring2、Hibernate3和Sitemesh是经典的Java Web开发框架组合,它们在构建企业级应用中发挥着重要作用。MyEclipse则是一款强大的集成开发环境,为这种组合提供了便捷的开发支持。 Struts2是MVC(模型-视图...
本实例主要涉及的技术栈包括SpringMVC、MyBatis、EhCache、FreeMarker以及Sitemesh,这些技术都是Java Web开发中的重要组件,各自承担着不同的职责。下面将分别详细介绍这些技术以及它们在整合中的作用。 1. ...
MiddleGen-Hibernate: 本书使用版本:2.1 官方网站:http://boss.bekk.no/boss/middlegen/ 下载页面:http://sourceforge.net/project/showfiles.php?group_id=36044 下载地址:...
Struts2.0+Hibernate+Spring是一个经典的Java Web开发技术栈,这一体系结构被广泛应用于构建企业级的Web应用程序,尤其是那些需要高效数据管理、强大业务逻辑和灵活控制层的系统。在这个“Struts2.0+Hibernate+...
标题 "Maven+SpringMVC+Hibernate4+Security+CXF+SiteMesh" 提到的是一种常见的企业级Java Web开发框架组合,这个架构通常用于构建高效、可维护且安全的Web应用程序。以下是对这些组件的详细说明: 1. **Maven**:...
sitemesh-2.4.2-src.jar 是sitemesh的源文件jar包,当调试时需要选择该jar包进行资源查找,很好用的页面架构工具
Struts2和Sitemesh是两个非常流行的Java Web开发框架,它们在构建高效、结构化的MVC(模型-视图-控制器)应用中起到关键作用。Struts2是一个基于MVC设计模式的开源框架,主要用于控制应用程序的流程,而Sitemesh则是...
WebWork+Spring+iBatis+Sitemesh是一个经典的Java Web应用程序开发框架组合,它们各自承担着不同的职责,共同构建了一个高效、灵活且可维护的Web应用系统。下面将详细介绍这四个组件及其在开发中的作用。 1. **...
jQuery+json+struts2+spring3(事务,AOP,IoC即DI)+hibernte3+EhCache+oscache+proxool+MySQL+SiteMesh+Gzip lj例子
sitemesh 2.4.2 weblogic 报错:Didn't meet stated Content-Length