zoukankan      html  css  js  c++  java
  • (Struts2学习系列五)Struts2默认action

      当我们访问项目下一个不存在的Action的时候,页面就会报错,404找不到资源,这样对用户来说是非常不友好的,所以我们设置一个默认的Action,当找不到对应Action的时候,就会跳转到默认Action指定的页面。

      在配置Action的helloworld.xml中要这样配置默认Action:

    <?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>
        <package name="default" namespace="/" extends="struts-default" >
            <default-action-ref name="index"></default-action-ref>
            <action name="index">
                <result>/error.jsp</result>
            </action>
               <action name="*_*_*" method="{2}" class="{3}.{1}Action"> 
                   <result>/result.jsp</result>
                   <result name="add">/{2}.jsp</result>
                   <result name="update">/{2}.jsp</result>
               </action>
       </package>
    </struts>  

      访问url:http://localhost:8080/struts2Test2/ddd.action,没配置默认Action之前会报错,配置之后就能访问到error.jsp页面了。

      至于其他的资源访问,则输入的url格式为:(http://localhost:8080/项目名/Action的类名_method名_包名.action)

      http://localhost:8080/struts2Test2/HelloWorld_update_action.action

      http://localhost:8080/struts2Test2/HelloWorld_add_action.action

      

  • 相关阅读:
    poj 3243 Clever Y(BabyStep GiantStep)
    poj 2417 Discrete Logging
    poj 3481 Double Queue
    hdu 4046 Panda
    hdu 2896 病毒侵袭
    poj 1442 Black Box
    hdu 2815 Mod Tree
    hdu 3065 病毒侵袭持续中
    hdu 1576 A/B
    所有控件
  • 原文地址:https://www.cnblogs.com/lindaZ/p/5027717.html
Copyright © 2011-2022 走看看