zoukankan      html  css  js  c++  java
  • 【Struts2学习笔记(1)】Struts2中Action名称的搜索顺序和多个Action共享一个视图--全局result配置


    一、Action名称的搜索顺序

    1.获得请求路径的URI,比如url是:http://server/struts2/path1/path2/path3/test.action


    2.首先寻找namespace为/path1/path2/path3的package,假设不存在这个package则运行步骤3;假设存在这个package,则在这个package中寻找名字为test的action。当在该package下寻找不到action 时就会直接跑到默认namaspace的package里面去寻找action(默认的命名空间为空字符串“” ) ,假设在默认namaspace的package里面还寻找不到该action,页面提示找不到action 


    3.寻找namespace为/path1/path2的package,假设不存在这个package,则转至步骤4;假设存在这个package。则在这个package中寻找名字为test的action。当在该package中寻找不到action 时就会直接跑到默认namaspace的package里面去找名字为test的action ,在默认namaspace的package里面还寻找不到该action。页面提示找不到action 


    4.寻找namespace为/path1的package,假设不存在这个package则运行步骤5;假设存在这个package,则在这个package中寻找名字为test的action,当在该package中寻找不到action 时就会直接跑到默认namaspace的package里面去找名字为test的action ,在默认namaspace的package里面还寻找不到该action,页面提示找不到action 


    5.寻找namespace为/的package,假设存在这个package,则在这个package中寻找名字为test的action。当在package中寻找不到action或者不存在这个package时,都会去默认namaspace的package里面寻找action。假设还是找不到。页面提示找不到action。


    二、多个Action共享一个视图--全局result配置

    当多个action中都使用到了同样视图,这时我们应该把result定义为全局视图。struts1中提供了全局forward,struts2中也提供了相似功能:

    <package ....>
    	<global-results>
    		<result name="message">/message.jsp</result>
    	</global-results>
    </package>



  • 相关阅读:
    Leetcode: Word Ladder II
    Leetcode: Triangle
    Leetcode: Best Time to Buy and Sell Stock II
    Leetcode: Best Time to Buy and Sell Stock
    Leetcode: Pascal's Triangle II
    Leetcode: Pascal's Triangle
    Leetcode: Path Sum II
    Leetcode: Convert Sorted Array to Binary Search Tree
    Leetcode: Merge Sorted Array
    Leetcode: Word Search
  • 原文地址:https://www.cnblogs.com/bhlsheji/p/5271442.html
Copyright © 2011-2022 走看看