zoukankan      html  css  js  c++  java
  • Struts ForwardAction Example

    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.

    struts-forwardaction-example1

    It will forward to http://localhost:8080/StrutsExample/Welcome.do
    struts-forwardaction-example2

  • 相关阅读:
    python--总结04-2---并发及数据库
    python--总结04-1---并发及数据库
    python--总结03--面向对象及网络
    python---总结01--基础
    python---总结02--函数
    mysql的join操作
    Bash 中的特殊字符大全
    Linux中软件的安装和卸载命令
    MFC 多窗口通信时,使用RadioButton和Button时冲突问题
    MFC中处理UI界面时的注意点
  • 原文地址:https://www.cnblogs.com/ghgyj/p/4766293.html
Copyright © 2011-2022 走看看