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. [HihoCoder1169]猜单词

    题目大意: 给你一个数列,问区间[l,r]内与k最接近的数与k的差是多少. 思路: 将数列中的数和询问的数先从小到大排序, 从小到大枚举每个数,如果是数列上的,就加到线段树中, 如果是询问中的,就在线 ...

  2. redisson实现基于业务的互斥锁

    虽然数据库有锁的实现,但是有时候对于数据的操作更需要业务层控制. 这个解决的问题有次面试被问到过,当时不知道怎么解决,乱说一通,今天也算是有个解决方案了 项目中有个需求,就是订单需要经过一层一层的审核 ...

  3. Codeforces Beta Round #10 A. Power Consumption Calculation 水题

    A. Power Consumption Calculation 题目连接: http://www.codeforces.com/contest/10/problem/A Description To ...

  4. hdu 5204 Rikka with sequence 智商不够系列

    Rikka with sequence Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.p ...

  5. 用rem设置文字大小

    一.px与em 用px设置文字大小是再正常不过的事情,比如 html {font-size: 12px;} 随处可见的在设置width.height使用px,这也是细致稳妥的设置方法,这样做的缺点在于 ...

  6. ida plug-in helloworld

    #include <ida.hpp> #include <idp.hpp> #include <loader.hpp> #include <kernwin.h ...

  7. java计算代码执行时间

    有时候为了排查性能问题,需要记录完成某个操作需要的时间,我们可以使用System类的currentTimeMillis()方法来返回当前的毫秒数,并保存到一个变量中,在方法执行完毕后再次调用 Syst ...

  8. CMAKE MYSQL

    http://www.blogjava.net/kelly859/archive/2012/09/04/387005.html

  9. SLF4J和Logback日志框架详解

    SLF4J和Logback日志框架详解 作者:chszs,转载需注明.博客主页:http://blog.csdn.net/chszs 本文讲述SLF4J和Logback日志框架.   SLF4J是一套 ...

  10. ArcGIS Engine中空间参照(地理坐标)相关方法总结转

    ArcGIS Engine中空间参照(地理坐标)相关方法总结 来自:http://blog.csdn.net/u011170962/article/details/38776101 1.创建空间参考 ...