In Struts MVC model, you have to go thought the Action Controller to get a new view page. In some cases, you really just need to get a specified JSP page only, it’s so stupid to create an action controller class which just forward the page to you, for example

public ActionForward execute(ActionMapping mapping,ActionForm form,
HttpServletRequest request,HttpServletResponse response)
throws Exception { return mapping.findForward("success");
}
   <action path="/Welcome"
type="com.mkyong.common.action.WelcomeAction">
<forward name="success" path="/Welcome.jsp"/>
</action>

Struts comes with a special action controller class called ForwardAction (org.apache.struts.actions.ForwardAction), to do the “forward-only” task as name described, and allow you to access the specified JSP page directly.

Example

Declare a “/Welcome” web path, type attribute as ForwardAction class, and forward it to Welcome.jsp page.

struts-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_3.dtd"> <struts-config> <action-mappings> <action
path="/Welcome"
type="org.apache.struts.actions.ForwardAction"
parameter="/pages/Welcome.jsp"/> </action-mappings> </struts-config>

Welcome.jsp

This is Welcome Page

Create a index.jsp page, when user click on the link, it will forward to “/Welcome” (return Welcome.jsp)

<%@taglib uri="http://struts.apache.org/tags-html" prefix="html"%>

ForwardAction Example

           Click me to access to JSP Welcome page

http://localhost:8080/StrutsExample/ , click on the link.

It will forward to http://localhost:8080/StrutsExample/Welcome.do

Struts ForwardAction Example的更多相关文章

  1. Struts之ForwardAction

    在Struts中,通过action跳转jsp,但是有时希望仅仅只是跳转页面,而不需要action,这时可以用ForwardAction. 定义一个仅仅是跳转的ForwardAction如下: < ...

  2. Struts核心技术简介

    Struts核心技术简介 1.Struts内部机制   Struts是一种基于MVC经典设计模式的开发源代码的应用框架,它通过把Servlet.JSP.JavaBean.自定义标签和信息资源整合到一个 ...

  3. Struts 笔记 内部资料 请勿转载 谢谢合作

    Struts 概述 随着MVC 模式的广泛使用,催生了MVC 框架的产生.在所有的MVC 框架中,出现最早,应用最广的就是Struts 框架. Struts 的起源 Struts 是Apache 软件 ...

  4. 教你如何精通Struts:Tiles框架

    Tiles框架特性和内容 Tiles框架为创建Web页面提供了一种模板机制,它能将网页的布局和内容分离.它允许先创建模板,然后在运行时动态地将内容插入到模板中.Tiles 框架建立在JSP的inclu ...

  5. Struts – Multiple configuration files example

    Many developers like to put all Struts related stuff (action, form) into a single Struts configurati ...

  6. Configure a welcome page in Struts

    Every website need a welcome or default page as an entry point. Here's 3 ways to configure a welcome ...

  7. SSH—Struts(三)—跑步者(Action)

    如已经描述Struts其基本原理和控制器ActionServlet,根据一个请求通过流ActionServlet之后就要到达Action类中做详细的处理了.ActionServlet通过ActionM ...

  8. struts2.1.6教程二、struts.xml配置及例程

    1.配置文件的优先级 在struts2中一些配置(比如常量)可以同时在struts-default.xml(只读性),strtus-plguin.xml(只读性),struts.xml,struts. ...

  9. 层层递进Struts1(三)之Struts组成

    这篇博客我们来说一下Struts的主要组成我们,通过前几篇博客,我们知道这个框架最重要的几个步骤:获取路径.封装表单.获取转向列表.转向逻辑处理.转向,与此对应的是:ActionServlet.Act ...

随机推荐

  1. hibernate annotation配置经验

    1.将annotation写在entity类文件的get方法上面

  2. LA 4725 (二分) Airport

    题意: 有W.E两个跑道,在每个时刻每个跑道的飞机都从0开始编号,而且每个时刻都有Wi和Ei架飞机到达这两个跑道.而且每个时刻只能选择一个跑道的一架飞机起飞.问如何选择才能使得飞机的最大编号最小.(每 ...

  3. ecshop 在首页每个商品下显示已销售数量

    1.在includes/lib_goods.php文件末尾加入以下代码 function get_buy_sum($goods_id) { $sql = "select sum(goods_ ...

  4. JBPM4入门——6.流程实例的创建和执行

    本博文只是简要对JBPM4进行介绍,如需更详细内容请自行google 链接: JBPM入门系列文章: JBPM4入门——1.jbpm简要介绍 JBPM4入门——2.在eclipse中安装绘制jbpm流 ...

  5. 查一下 excel中某一列是否有重复

    另一列中写入 =IF(COUNTIF(C:C,C1)>1,"有重复","") 其余往下拖拉公式 我在想如果可以有不往下拖的呢? 不过好像筛选中也有类似的选 ...

  6. Java并发编程-关卡

    CyclicBarrier 直译过来叫循环栅栏,它主要的方法就是一个:await().await() 方法没被调用一次,计数便会减少1,并阻塞住当前线程.当计数减至0时,阻塞解除,所有在此 Cycli ...

  7. RedHat 5 配置CentOS yum 更新源

    YUM是Redhat Linux在线安装更新及软件的工具,但是这是RHEL5的收费功能,如果没有购买Redhat的服务时不能使用RHEL5的更新源的,会提示注册. 由于CentOS是从Redhat演化 ...

  8. win下 golang 跨平台编译

    mac 下编译其他平台的执行文件方式请参看这篇文章,http://www.cnblogs.com/ghj1976/archive/2013/04/19/3030703.html  本篇文章是win下的 ...

  9. 【LR】安装LR11后遇到的问题

    (1)问题:录制脚本时无法弹出IE浏览器 解决方法: 正确的是C:\Program Files (x86)\Internet Explorer\iexplore.exe 错误是:C:\Program ...

  10. 【转】linux之tune2fs命令

    转自:http://czmmiao.iteye.com/blog/1749232 tune2fs简介 tune2fs是调整和查看ext2/ext3文件系统的文件系统参数,Windows下面如果出现意外 ...