struts2的struts.xml简单介绍

来源:互联网 发布:300339润和软件 编辑:程序博客网 时间:2024/05/17 09:17

啊    昨天其实就发现了的,struts的MVC结构非常的正规,感觉这样处理起来确实是将各个问题都分开解决了,谁也不会影响谁的,后台的处理后台,前台的处理前台。关于这里的链接这些东西的就是struts.xml了,这个东西是非常重要的,你要配置好这个xml文件才能将整个MVC架构起来!

       下面说一下,几个比较重要的知识点:第一、就是默认的action,就是如果没有找到对应的action,你要访问那个界面,通常我们是要报错的,那么你就可以设置一个简单的报错网页,随时告知自己是action没有导致的,对于找错误也是很有帮助的;第二、result中的type值,可以设置result动作的类型,当然redirect是最好的,我认为,当然也要根据具体的情况来说。第三、通配符的使用,这个也是很方便的,如果你的result返回的网页就那么几个网页,或者action的名字和method有一些关系,那通配符是一个好东西的。第四、global-results不能和default-action-ref一起用,这个不知道是怎么回事,网上没有找到答案。

把我的struts.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"><struts><constant name="struts.devMode" value="true"></constant> <!-- 发布的时候是要把这个false掉的 --><package name="struts2" extends="struts-default" ><!--  <global-results><result name="error" type="redirect">/chapter8/error.jsp</result></global-results>--> <!-- 这个和defult-action-ref不能一起用 --><default-action-ref name="forwardaction">apter8/error.jsp</default-action-ref><action name="forwardaction" class="chapter8.action.DefaultAction"><result name="error" type="redirect">apter8/error.jsp</result></action><action name="login" class="chapter8.action.QueryAction" method="login"><result name="loginsuccess" >/chapter8/loginsuccess.jsp</result><result name="loginnotfound">/chapter8/loginnotfound.jsp</result></action><action name="register" class="chapter8.action.QueryAction" method="register"><result name="registersuccess">/chapter8/registersuccess.jsp</result></action></package></struts>    


原创粉丝点击