zoukankan      html  css  js  c++  java
  • Struts2------通配符

    <struts>
        <package namespace="/" extends="struts-default" name="test" >
            <action name="test_*" class="com.test.action.Test" method="{1}">
                <result name="{1}">views/test_{1}.jsp</result>
            </action>
        </package>
    </struts>

    先解释一下上面绿标的代码

    1) test_*:中*代表访问地址可以为test_world,test_hello或test_#等但是不能用 / 和 . 其中#号访问的是execute()

    2) method="{1}:中{1}表示从地址栏获取到的访问路径
      比如:输入地址为 http://localhost:8080/testStruts2/test_save 那么{1}的值为save

      以此类推其余的{1}的参数
        name="{1}"等于name="save"
        views/test_{1}.jsp等于 views/test_save.jsp

    解释清楚接下来就容易理解了
    先看目录结构:


    jsp统一<body>这是XXXX.jsp</body>

    再看访问效果

    地址:http://localhost:8080/testStruts2/test_save
    结果:這是test_save.jsp
    地址:http://localhost:8080/testStruts2/test_update
    结果:這是test_update.jsp
    地址:http://localhost:8080/testStruts2/test_delete
    结果:這是test_delete.jsp

    总结:命名约束好可以用一下 减少配置 提高效率
        上述*可以多个*_*_*获取{1}_{2}_{3} 获取是从一开始
     
     
    选择一种风格,保持这种风格。
  • 相关阅读:
    我的WCF之旅(1):创建一个简单的WCF程序
    网页设计中颜色的搭配
    CSS HACK:全面兼容IE6/IE7/IE8/FF的CSS HACK
    UVa 1326 Jurassic Remains
    UVa 10340 All in All
    UVa 673 Parentheses Balance
    UVa 442 Matrix Chain Multiplication
    UVa 10970 Big Chocolate
    UVa 679 Dropping Balls
    UVa 133 The Dole Queue
  • 原文地址:https://www.cnblogs.com/chenchen-fei/p/5554886.html
Copyright © 2011-2022 走看看