分类: 系统运维
2012-01-24 23:25:40
action1.jsp
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
>
Action1.java
package com.shengsiyuan.struts2;
import com.opensymphony.xwork2.ActionSupport;
public class Action1 extends ActionSupport
{
private String username;
private String password;
private String usernameAndPassword;
public String getUsernameAndPassword()
{
return usernameAndPassword;
}
public void setUsernameAndPassword(String usernameAndPassword)
{
this.usernameAndPassword = usernameAndPassword;
}
public String getUsername()
{
return username;
}
public void setUsername(String username)
{
this.username = username;
}
public String getPassword()
{
return password;
}
public void setPassword(String password)
{
this.password = password;
}
@Override
public String execute() throws Exception
{
this.usernameAndPassword = this.username + this.password;
return SUCCESS;
}
public String myExecute() throws Exception
{
System.out.println("myExecute invoke");
return SUCCESS ;
}
}
struts.xml部分
action2
${username}
${password}
${usernameAndPassword}
execute,myExecute
TheInterceptor3.java
package com.shengsiyuan.interceptor;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;
import com.shengsiyuan.listener.TheListener;
public class TheInterceptor3 extends MethodFilterInterceptor
{
@Override
protected String doIntercept(ActionInvocation invocation) throws Exception
{
invocation.addPreResultListener(new TheListener()) ;
System.out.println("before interceptor3");
String result = invocation.invoke() ;
System.out.println("after interceptor3");
return result ;
}
}
TheListener.java
package com.shengsiyuan.listener;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.PreResultListener;
public class TheListener implements PreResultListener
{
public void beforeResult(ActionInvocation invocation, String resultCode)
{
System.out.println("result code:" + resultCode);
}
}