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()方法。

 

STRUTS2配置动态页面的更多相关文章

  1. [置顶] 自己动手写Web容器之TomJetty之六:动态页面引入

    传送门 ☞ 1.Web服务内功经脉 传送门 ☞ 2.让服务动起来 传送门 ☞ 3.掀起请求盖头来 传送门 ☞ 4.静态页面起步 传送门 ☞ 5.包装请求参数 在上一节,我们已经完成了TomJetty服 ...

  2. Struts2的动态Action和全局跳转视图以及配置各项默认值

    1:Struts2的默认访问后缀是.action(特别需要注意的是改了配置文件web.xml或者struts.xml需要重启服务器) 2:Struts2中常用的常量介绍:<!-- 一:全局配置 ...

  3. Spring MVC 学习总结(七)——FreeMarker模板引擎与动态页面静态化

    模板引擎可以让程序实现界面与数据分离,业务代码与逻辑代码的分离,这就提升了开发效率,良好的设计也使得代码复用变得更加容易.一般的模板引擎都包含一个模板解析器和一套标记语言,好的模板引擎有简洁的语法规则 ...

  4. Struts2 配置详解

    1. web.xml 此文件的配置可以参看struts2的示例文档 <filter> <filter-name>struts2</filter-name> < ...

  5. Struts2配置详解_配置Action

    Struts2的核心功能是action,对于开发人员来说,使用Struts2主要就是编写action,action类通常都要实现com.opensymphony.xwork2.Action接口,并实现 ...

  6. 动态页面技术JSP/EL/JSTL

    本节内容: jsp脚本和注释 jsp运行原理 jsp指令(3个) jsp内置/隐式对象(9个) jsp标签(动作) EL技术 JSTL技术 JavaEE的开发模式 动态页面技术:就是在html中嵌入j ...

  7. Struts2 配置Action详解

     Struts2的核心功能是action,对于开发人员来说,使用Struts2主要就是编写action,action类通常都要实现com.opensymphony.xwork2.Action接口,并实 ...

  8. Struts2的动态Action实现

    源自:Struts2的动态Action实现 在Struts2中动态方法调用有三种方式. 一.指定method属性在struts.xml中指定action的method属性. <package n ...

  9. 2018.12.15 struts.xml 一般配置文件写法 && 配置动态方法

    struts.xml 原始配置文件 配置 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE s ...

随机推荐

  1. LCA POJ 1330 Nearest Common Ancestors

    POJ 1330 Nearest Common Ancestors Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 24209 ...

  2. Codeforces Round #348 (VK Cup 2016 Round 2, Div. 1 Edition) C. Little Artem and Random Variable 数学

    C. Little Artem and Random Variable 题目连接: http://www.codeforces.com/contest/668/problem/C Descriptio ...

  3. Codeforces Beta Round #92 (Div. 1 Only) A. Prime Permutation 暴力

    A. Prime Permutation 题目连接: http://www.codeforces.com/contest/123/problem/A Description You are given ...

  4. SpringMVC 3.1.1版本下的单元测试WEB-INF路径问题

    假设Spring配置文件为applicationContext.xml 一.Spring配置文件在类路径下面 在Spring的java应用程序中,一般我们的Spring的配置文件都是放在放在类路径下面 ...

  5. JQ 使用模板

    1.首先需要添加模板JS文件,

  6. tomcat使用Eclipse进行远程调试(线上调试)

    什么是远程调试,就是在A机器上利用Eclipse单步跟踪调试B机器上的Web应用,当然调试A机器上Web应用也是没有问题的,90%我都是调试本机的Web应用,远程调试的意义我想我不用说了,大家都会想到 ...

  7. ubuntu 包管理详解

    http://www.cnblogs.com/forward/archive/2012/01/10/2318483.html

  8. 阻止picker.js插件弹出键盘

    <input id="focus" type="text" value="" placeholder="手机号" ...

  9. MySQL MyISAM和InNodb备份与恢复技巧

    1. 为什么要备份数据库 对数据库来说,最重要也最容易被忽视的就是备份.由于不可预测性,偶然的事件可能会导致非常惨重的损失. 数据越是重要,数据的变化越频繁,备份越发需要经常进行. 备份周期根据不同业 ...

  10. python笔记19-获取当前运行函数名称和类方法名称

    前言 写完代码之后,一般为了方便查看日志,可以在日志输出中加入当前运行的函数名称或类和方法名称,以便于代码报错的时候能快速找到报错的是哪个函数或方法. 那么如何获取当前运行函数(或方法)的名称呢? 获 ...