Struts2 동적 결과 세트

1539 단어 struts2.0
1、index.jsp
<body>
   set get 
<ol>
	<li><a href="user/user?type=1"> success</li>
	<li><a href="user/user?type=2"> error</li>	
</ol>
</body>

2.struts.xml
<struts> 
 <constant name="struts.devMode" value="true" /> 
 <package name="user" namespace="/user" extends="struts-default">        
        <action name="user" class="com.wxh.action.UserAction">
            <result >${r}</result>
        </action>    
    </package>
</struts>

3.UserAction.java
package com.wxh.action;
import com.opensymphony.xwork2.ActionSupport;
public class UserAction extends ActionSupport{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private int type;	
	private String r;
	public String getR() {
		return r;
	}
	public void setR(String r) {
		this.r = r;
	}
	public int getType() {
		return type;
	}
	public void setType(int type) {
		this.type = type;
	}
	// r 
	public String execute() throws Exception{
		if(type==1) r="/userSuccess.jsp";
		else if(type==2) r="/userError.jsp";
	    return "success";		
	}
}

4.userError.jsp
<body>
user error!
</body>

5.userSuccess.jsp
<body>
user Success!
</body>

좋은 웹페이지 즐겨찾기