zoukankan      html  css  js  c++  java
  • Struts2--Global Result全局结果集

    如果有很多action,有共同的result指向, 而且属于不同的包,那么可以继承上面的包, 然后写一个<global-results>

    1. jsp显示文件:

    <ol>
    	<li><a href="user/user?type=1">返回success</a></li>
    	<li><a href="user/user?type=2">返回error</a></li>
    	<li><a href="user/user?type=3">返回global result</a></li>
    	<li><a href="admin/admin">admin,继承user包</a></li>
    </ol>
    

    2. struts.xml:

    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
        "http://struts.apache.org/dtds/struts-2.0.dtd">
    <struts>
        <constant name="struts.devMode" value="true" />
        <package name="user" namespace="/user" extends="struts-default">
         	<global-results>
        		<result name="mainpage">/main.jsp</result>
        	</global-results>
        	
        	<action name="index">
        		<result>/index.jsp</result>
        	</action>
       	    <action name="user" class="com.bjsxt.struts2.user.action.UserAction">
    	    	<result>/user_success.jsp</result>
    	    	<result name="error">/user_error.jsp</result>
    	    </action>	    
        </package>
        
        <package name="admin" namespace="/admin" extends="user">
        	<action name="admin" class="com.bjsxt.struts2.user.action.AdminAction">
        		<result>/admin.jsp</result>
        	</action>
        </package>
    </struts>
    

    userAction.JAVA:

    package com.bjsxt.struts2.user.action;
    
    import com.opensymphony.xwork2.ActionSupport;
    
    public class UserAction extends ActionSupport {
    	private int type;
    	public int getType() {
    		return type;
    	}
    	public void setType(int type) {
    		this.type = type;
    	}
    	@Override
    	public String execute() throws Exception {
    		if(type == 1) return "success";
    		else if (type == 2) return "error";
    		else return "mainpage";
    	}
    }
    

    adminAction.java:

    package com.bjsxt.struts2.user.action;
    
    import com.opensymphony.xwork2.ActionSupport;
    
    public class AdminAction extends ActionSupport {
    
    	@Override
    	public String execute() throws Exception {
    		return "mainpage";
    	}
    
    }
    

      

      

     

     

  • 相关阅读:
    swift函数
    Swift数据类型
    swift的特点
    图片适配、九宫切图
    iOS中视图控制器的生命周期
    CocoaPods的安装与使用
    SQLite3的使用
    Pickers应用程序
    多视图应用
    OC对象的三大特性:封装、继承和 多态
  • 原文地址:https://www.cnblogs.com/wujixing/p/5202843.html
Copyright © 2011-2022 走看看