• (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

      

  • 相关阅读:
    mysql案例 ~ 监控以及如何避免从库延迟问题
    mysql基础~开发规范
    k8s系列~mgr的应用
    k8s系列~docker mysql
    常用知识点(一)
    Windows下查看进程状态/信息
    Lua入门(一)
    Lua简介
    .NET&C#的异常处理
    数据库中的锁
  • 原文地址:https://www.cnblogs.com/lindaZ/p/5027717.html
Copyright © 2020-2023  润新知