有时候在做struts2的返回页面时,不想让sitemesh装饰action所返回的某个特定的页面,比如:错误页面或者我们自己写的404页面。因为sitemesh是根据url来判断是否装饰的,如果你提交上去的action已经装饰了,那么这个action返回回来的result页面,自然就也会被装饰,因为此时地址栏的url没有变化。如果我们此时不想装饰返回的某个页面时,可以有以下解决方案:(有关sitemesh配置文件我就不做说明了,网上一大堆,呵呵^_^..以下是部分配置说明)
struts.xml部分配置:
<action name="toIndex" class="indexAction" method="toIndex">
<result name="index">/main.jsp</result>
<result name="error">/error.jsp</result>
</action>
我们不想对上面的error.jsp做装饰,那么我们要在error.jsp页面上加一句meta:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<!-- 不让sitemesh装饰此页面 :content="none"表示在decorators.xml里面的name="none"的装饰器 -->
<meta name="decorator" content="none"/>
<title>异常页面</title>
</head>
然后再在decorators.xml中配置一下:
<?xml version="1.0" encoding="UTF-8"?>
<decorators defaultdir="/layout">
<decorator name="none">
<pattern>/error.jsp*</pattern>
</decorator>
</decorators>
注意:上面的name="none"要和error.jsp页面中的meta "content"属性值一样。好了,配置完了,试试吧,肯定不会再被装饰了,^_^。。。
除了上面的解决方案之外,根据网友的提示,貌似在action中设置result的type="redirect"也可以,不过我没试,有兴趣的可以试试,呵呵。。谢谢大家,第一次发稿,请多指教。。
分享到:
相关推荐
Struts 2.0提供一个Sitemesh插件,允许在Sitemesh模板中使用Struts标记。 要使用Sitemesh需要包含Freemark,Sitemesh和Sitemesh插件库文件。 配置过滤器 如果需要使用Freemark模板文件作为装饰器文件,需要在web....
struts2-sitemesh-plugin-2.2.1.1.jarstruts2
struts2-sitemesh-plugin-2.1.6.jar
struts2-sitemesh-plugin-2.0.8.jar
一个Struts2+Spring2.5+SiteMesh的小DEMO,仅供大家做个参考!我也刚学会。欢迎大家多交流!
11.1.2 Struts 2如何解决本地Java对i18n支持的问题 243 11.2 Struts 2 i18n示例 244 11.2.1 Struts 2 i18n快速展示 244 11.2.2 幕后一览 246 11.3 Struts 2 i18n详情 247 11.3.1 Struts 2默认的TextProvider Re-...
NULL 博文链接:https://takeme.iteye.com/blog/1716488
SiteMesh 开发jar包 Struts2 SiteMesh 插件 jar包
struts2+sitemesh例子 该例子描述了struts2+sitemesh的配置,比较实用
struts2-sitemesh_入门收集struts2-sitemesh_入门收集
用sitemesh页面装饰器,将大名鼎鼎的开源即时通讯服务器openfire中运用的,布局页面抽取出来。MyEclipse中可以直接部署的代码。
测试用报表架构(sitemesh+struts2+birt)
Sitemesh是由一个基于Web页面布局、装饰以及与现存Web应用整合的框架。它能帮助我们在由大 量页面构成的项目中创建一致的页面布局和外观,如一致的导航条,一致的banner,一致的版权,等等。 它不仅仅能处理动态的...
sitemesh+ spring2 + struts2 + hibernate 的 demo
struts2sitemesh-freemarker 源码
struts2与sitemesh整合所需的两个最新架包sitemesh-2.4.2,struts2-sitemesh-plugin-2.1.8
struts2-sitemesh-plugin-2.1.8.1.jar
解决 java.lang.NoSuchFieldException: DEFAULT_PARAM>问题,下载后替换即可。
struts框架与sitemesh框架整合的插件,在java web开发中可以制作模板页,使自己做的网站看起来更专业
一旦Action执行完毕,ActionInvocation负责根据struts.xml中的配置找到对应的返回结果result。 Struts 2的核心控制器是FilterDispatcher,有3个重要的方法:destroy()、doFilter()和Init(),可以在Struts 2的下载...