STRUTS2配置动态页面 2025620编辑

Heaven helps those who help themselves
资深码农+深耕理财=财富自由
欢迎关注

STRUTS2配置动态页面

Created by Marydon on 2017-05-11 09:25

STRUTS2配置动态页面

CreateTime--2017年5月11日09:00:31
Author:Marydon

  1.struts配置 

复制代码
<?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>
    <!--  struts2配置  -->
    
    <!-- struts2常用配置 START -->
    <!--指定web应用的默认编码集,相当于调用HttpServletRequest.setCharacterEncoding方法 -->
    <constant name="struts.i18n.encoding" value="UTF-8" />
    <!-- 指定需要struts2处理的请求后缀,默认值为action. 如果用户需要指定多个请求后缀,则多个后缀之间以英语逗号(,)隔开 -->
    <constant name="struts.action.extension" value="do" />
    
    <!--当struts.xml文件改变后,系统是否自动的重新加载该文件,默认值为false -->
    <constant name="struts.configuration.xml.reload" value="true" />
    
    <!--
        是否应用开发模式. 通常,应在开发阶段设置为true,出错时显示更多、更友好的出错提示; 当进入产品发布阶段后,应该设置为false
    -->
    <constant name="struts.devMode" value="true" />
    <!--当找不到url时是否根据namespace向上级路径查询,默认值为false -->
    <constant name="struts.mapper.alwaysSelectFullNamespace" value="true"></constant>
    <!--配置上传文件大小 -->
    <constant name="struts.multipart.maxSize" value="10000000" />
    <constant name="struts.multipart.saveDir " value="" />
    <!--
        该属性指定Struts 2框架默认加载的配置文件,如果需要指定默认加载多个配置文件, 则多个配置文件的文件名之间以英文逗号(,)隔开。
        该属性的默认值为struts-default.xml,struts-plugin.xml,struts.xml
    -->
    <constant name="struts.configuration.files" value="struts-default.xml" />
    <!-- END struts2常用配置 -->
    
    <!-- 配置动态页面 -->
    <constant name="struts.enable.DynamicMethodInvocation" value="true"></constant>
    
    <package name="PATIENT" extends="struts-platform" namespace="/telemedicine/patient">
        <!-- 查询
                已申请的*、已安排的*、未通过的*、已撤销的*、*审核、*报告、未完成的*、已完成的*、*效果评价
             所对应的列表页面
        -->
        <action name="index" class="telemedicine.web.actions.reseCons.PATIENT_Action" method="index">
            <!-- 动态页面 -->
            <result name="success" type="dispatcher">${dispatcherPath1}</result>
        </action>
    </package>
</struts>
复制代码

  2.Action类配置

复制代码
  //首页页面转发路径
    private String dispatcherPath1;
    //生成对应的get、set方法
    public String getDispatcherPath1() {
        return dispatcherPath1;
    }

    public void setDispatcherPath1(String dispatcherPath1) {
        this.dispatcherPath1 = dispatcherPath1;
    }

    // 转发路径
    String dPath = "";
    // 状态:根据不同的状态值设置不同的页面路径
    // 自定义状态(用于区分跳转页面) 1:已申请的*;2:已撤销的*;3:*审核;4:未通过的*;
    // 5:已安排的*;6:未完成的*;7:*报告;8:已完成的*;9:*效果评价(9 未定)
    String modelAndView = "";
    
    /**
     * *审核信息表
     * @return 导航到首页
     */
    public String index() {
      try {
          // 必要参数:跳转页面-modelAndView
          paramsMap = WebUtils.getParameterMap();
          // modelAndView为必要参数
          if (paramsMap.containsKey("modelAndView")) {
            // 自定义状态(用于区分跳转页面) 1:已申请的*;2:已撤销的*;3:*审核;4:未通过的*;
            // 5:已安排的*;6:未完成的*;7:*报告;8:已完成的*;9:*效果评价(9 未定)
            modelAndView = paramsMap.get("modelAndView").toString().trim();

            if ("1".equals(modelAndView))
                dPath = "/telemedicine/remoteRese/consAlready/consAleady_records.jsp";// 已申请的*
            else if ("2".equals(modelAndView))
                dPath = "/telemedicine/remoteRese/consRevoked/consRevoked_records.jsp";// 已撤销的*
            else if ("3".equals(modelAndView))
                dPath = "/telemedicine/remoteCons/consReview/consReview_records.jsp";// *审核
            else if ("4".equals(modelAndView))
                dPath = "/telemedicine/remoteRese/consNopass/consNopass_records.jsp";// 未通过的*
            else if ("5".equals(modelAndView))
                dPath = "/telemedicine/remoteRese/consPlannad/consPlannad_records.jsp";// 已安排的*
            else if ("6".equals(modelAndView))
                dPath = "/telemedicine/remoteCons/consUncomp/consUncomp_records.jsp";// 未完成的*
            else if ("7".equals(modelAndView))
                dPath = "/telemedicine/remoteCons/consReport/consReport_records.jsp";// *报告
            else if ("8".equals(modelAndView))
               dPath = "/telemedicine/remoteCons/consComp/consComp_records.jsp";// 已完成的*
            else if ("9".equals(modelAndView))
                dPath = "/telemedicine/remoteCons/consEval/consEval_records.jsp";// *效果评价

            // 设置跳转页面路径
            this.setDispatcherPath1(dPath);
          }
        } catch (Exception e) {
          this.code = -1;
          this.msg = e.getMessage();
          this.expMsg = getExceptionMessage(e);
          log.error(e.getMessage());
      }
      return getResult();
    }
复制代码

  要点解析:

    1.struts转发路径用"${动态值}"代替死值;

    2.在Action类中生成动态值的get(),set()方法。

 

与君共勉:最实用的自律是攒钱,最养眼的自律是健身,最健康的自律是早睡,最改变气质的自律是看书,最好的自律是经济独立 。

您的一个点赞,一句留言,一次打赏,就是博主创作的动力源泉!

↓↓↓↓↓↓写的不错,对你有帮助?赏博主一口饭吧↓↓↓↓↓↓

posted @   Marydon  阅读(620)  评论(0编辑  收藏  举报
编辑推荐:
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 提示词工程——AI应用必不可少的技术
· 字符编码:从基础到乱码解决
· 地球OL攻略 —— 某应届生求职总结
点击右上角即可分享
微信分享提示
sorry,本博客所有代码禁止复制,原创代码需扫码支付方可获取!
关闭

1、先加好友再付费,点我加好友;

2、代码不能满足你的需求?加好友付费定制你的专属代码!

3、付费标准及方式,点我查看详情。