`
zxt1985
  • 浏览: 20786 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

关于sitemesh不装饰struts2中action返回页面解决方案。

阅读更多
有时候在做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"也可以,不过我没试,有兴趣的可以试试,呵呵。。谢谢大家,第一次发稿,请多指教。。
4
0
分享到:
评论
2 楼 helongno1 2013-01-22  
我按照你的方法,怎么试都出不来,为什么呀?
1 楼 baojyy1 2012-06-15  
太感谢了  

相关推荐

Global site tag (gtag.js) - Google Analytics