Chinaunix首页 | 论坛 | 博客
  • 博客访问: 335227
  • 博文数量: 96
  • 博客积分: 2041
  • 博客等级: 大尉
  • 技术积分: 1080
  • 用 户 组: 普通用户
  • 注册时间: 2012-01-20 14:08
文章分类

全部博文(96)

文章存档

2015年(2)

2013年(1)

2012年(93)

分类: 系统运维

2012-01-24 23:25:40

action1.jsp

<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
 
 

   


    username:

    password:

   
   
>
 

 

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);

    }

}

阅读(4340) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~