Struts2 配置文件


当前第2页 返回上一页

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
     <include file="my-struts1.xml"/>
     <include file="my-struts2.xml"/>
</struts>

我们没有覆盖的另一个配置文件是struts-default.xml。此文件包含Struts的标准配置设置,你不必再为99.99%的项目重复这些设置。 因此,我们不会深入了解这个文件的太多细节。如果你有兴趣,可以查看在struts2-core-2.2.3.jar文件中可用的default.properties文件。

struts-config.xml文件

struts-config.xml配置文件是Web Client中View和Model组件之间的链接,但在你99.99%的项目里你不必使用这些设置。 struts-config.xml配置文件包含以下主要元素:

序号 拦截器和说明
1 struts-config

这是配置文件的根节点。

2 form-beans

这是你将ActionForm子类映射到name的位置,你可以在struts-config.xml文件的其余部分,甚至在JSP页面上,将这个name用作ActionForm的别名。

3 global forwards

此部分将你在webapp上的页面映射到name,你可以使用这个name来引用实际页面。这避免了对你网页上的URL进行硬编码。

4 action-mappings

这是你声明表单处理程序的地方,也被称为操作映射(action mappings)

5 controller

这部分是配置Struts的内部,在实际情况中很少使用。

6 plug-in

这部分告诉Struts在哪里找到属性文件,它包含提示和错误消息。

下面是struts-config.xml文件的示例:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.0//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_0.dtd">

<struts-config>

   <!-- ========== Form Bean Definitions ============ -->
   <form-beans>
      <form-bean name="login" type="test.struts.LoginForm" />
   </form-beans>

   <!-- ========== Global Forward Definitions ========= -->
   <global-forwards>
   </global-forwards>

   <!-- ========== Action Mapping Definitions ======== -->
   <action-mappings>
      <action
         path="/login"
         type="test.struts.LoginAction" >

         <forward name="valid" path="/jsp/MainMenu.jsp" />
         <forward name="invalid" path="/jsp/LoginView.jsp" />
      </action>
   </action-mappings>

   <!-- ========== Controller Definitions ======== -->
   <controller 
      contentType="text/html;charset=UTF-8"
      debug="3"
      maxFileSize="1.618M"
      locale="true"
      nocache="true"/>

</struts-config>

有关struts-config.xml文件的更多详细内容,可查看Struts Documentation。

struts.properties文件

这个配置文件提供了一种机制来改变框架的默认行为。实际上,struts.properties配置文件中包含的所有属性也可以在web.xml中配置使用init-param,以及在struts.xml配置文件中使用constant标签。 但如果你想保持事件独立以及保留更多struts细节,那么你可以在WEB-INF/classes文件夹下创建这个文件。

struts.properties

文件中配置的值将覆盖

default.properties

中配置的默认值,这些值包含在struts2-core-x.y.z.jar分布中。有一些属性,你可以考虑改为使用

struts.properties

文件:

### When set to true, Struts will act much more friendly for developers
struts.devMode = true

### Enables reloading of internationalization files
struts.i18n.reload = true

### Enables reloading of XML configuration files
struts.configuration.xml.reload = true

### Sets the port that the server is run on
struts.url.http.port = 8080

这里任何以#(hash)开头的行都将被假定为注释,并且它会被Struts 2默认忽略。



标签:Struts2

返回前面的内容

相关阅读 >>

Struts2 发送电子邮件

Struts2 表单标签

Struts2 主题和模板

Struts2 异常处理

Struts2 概述

Struts2 结果类型

Struts2 ajax标签

Struts2 架构

Struts2 hello world示例

Struts2 类型转换

更多相关阅读请进入《Struts2》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...