zoukankan      html  css  js  c++  java
  • struts学习struts.xml

    我的博客:www.while0.com

    我的博客:www.shishangguan.net

    年后归来,继续学习struts。

    struts中struts.xml的关联方式

    在struts1中struts.xml需要在web.xml中关联struts.xml,且struts.xml必须和web.xml放到WEB-INF目录的根目录下边,关联方式如下:

    1 - <init-param>
    2   <param-name>config</param-name> 
    3   <param-value>/WEB-INF/struts-config.xml</param-value> 
    4   </init-param>

    如果有多个配置文件需要用,隔开。而在struts2中,则不需要在web.xml中关联,只需要把struts.xml放到WEB-INF/src目录下边即可。如果要关联多个,则在struts.xml中使用include标签来关联多个

    1 <include file="example.xml" /> 

    注意:struts1中是使用servlet方式启动struts,struts2中则使用filter启动struts

     要把eclipse的web工程放到tomcat的webapp目录去运行需要打包成war文件。具体方法为file->export.

    在struts.xml中,包必须继承default,这样才能使用拦截器的功能。如下

    1    <package name="example"  namespace="/example" extends="default"> //必须继承default  如果abstract=true,则该package中不能包含action
    2 
    3         <action name="HelloWorld" class="example.HelloWorld">
    4             <result>/HelloWorld.jsp</result>
    5         </action>
    6 
    7         <!-- Add actions here -->
    8     </package>

    struts中action的搜索顺序:

    http://localhost:8080/struts/path1/path2/path3/test.action为例,

    先搜索/path1/path2/path3下边是否有test.action,如果没有搜索/path1/path2下边是否有test.action,如果没有
    搜索/path1下边是否有test.action,如果还没有
    则在默认命名空间,即namespace=""的package下搜索。

    struts中常见缺省设置

    action中,如果class为空,则缺省class为ActionSupport。如果method为空,则缺省为execute().

    result中,如果name为空,则缺省name为success

    struts中为action注入值

    1  <package name="test" namespace="/test" extends="struts-default">
    2     
    3         <action name="param" class="test.Param">
    4             <result>/WEB-INF/test/param.jsp</result>
    5             <param name="id">zhangxiaomin</param><!--如果在url中未给定id属性的值,则id的默认值为zhangxiaomin-->
    6         </action>
    7 
    8     </package>

    struts中更改后缀

    1 <constant name="struts.action.extension" value="do,action" />
    2 <!-- 多个后缀用','分割开来-->
  • 相关阅读:
    Mapreduce学习(一)
    Codeforces Global Round 10题解(A-D)
    八月第二周总结
    hdfs学习(三)
    Educational Codeforces Round 93 (Rated for Div. 2)题解
    hdfs学习(二)
    牛客团队赛50&CF#664(Div2)
    hdfs学习(一)
    蓝桥杯刷题(二)
    Kubernetes K8S之Pod 生命周期与postStart、preStop事件
  • 原文地址:https://www.cnblogs.com/yamadie/p/2913149.html
Copyright © 2011-2022 走看看