---
title: "struts2拦截器详解实例"
author: "netxdiy"
date: "2011-03-21T16:11:55Z"
tags: ["Apache", "HTML", "JSP", "Java", "Struts"]
categories: ["企业架构"]
slug: "struts2"
draft: false
lastmod: "2011-03-21T16:13:02Z"
id: 969507
url: "https://netxdiy.iteye.com/blog/969507"
---

struts.xml /input.jsp /addOK.jsp /error.jsp input.jsp &lt;%@ page language="java" import="java.util.\*" pageEncoding="UTF-8"%&gt; &lt;% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %&gt; &lt;%@taglib uri="/struts-tags" prefix="s" %&gt;  My JSP 'test.jsp' starting page

name: age:

InputAction.java package com.bjsxt.action; import com.opensymphony.xwork2.ActionSupport; public class InputAction extends ActionSupport { @Override public String execute() throws Exception { return super.execute(); } } UserAction.java package com.bjsxt.action; import com.opensymphony.xwork2.ActionSupport; public class UserAction extends ActionSupport { private String name; private int age; @Override public String execute() throws Exception { System.out.println("a user added!"); return super.execute(); } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } } addOK.jsp &lt;%@ page language="java" import="java.util.\*" pageEncoding="UTF-8"%&gt; &lt;% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %&gt;  My JSP 'test.jsp' starting page addOK  
error.jsp &lt;%@ page language="java" import="java.util.\*" pageEncoding="UTF-8"%&gt; &lt;% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %&gt;  My JSP 'test.jsp' starting page 严禁做重复的事！