//以下属性信息都是从前台(JSP页面获得)
private String username;
private String mymsg;
private String password1;
private String password2;
private Date birthday;
public String execute(){
if(username!=null&&this.getPassword1().equals(this.getPassword2())&&!this.getUsername().trim().equals("")){
//输出调试信息
System.out.println("Action信息,正在执行Action.... ");
return SUCCESS;
}else{
return INPUT;
}
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getMymsg() {
return mymsg;
}
public void setMymsg(String mymsg) {
this.mymsg = mymsg;
}
public String getPassword1() {
return password1;
}
public void setPassword1(String password1) {
this.password1 = password1;
}
public String getPassword2() {
return password2;
}
public void setPassword2(String password2) {
this.password2 = password2;
}
public Date getBirthday() {
return birthday;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
}
//拦截方法
public String intercept(ActionInvocation invocation) throws Exception {
MyAction myA=(MyAction) invocation.getAction();
System.out.println("拦截器信息:hello world 拦截器");
//执行action或者下一个拦截器
String result=invocation.invoke();
System.out.println("拦截器信息:Action执行完毕");
return result;
}
}
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="mynew" namespace="/" extends="struts-default">
<interceptors>
<interceptor name="myInterceptor" class="com.MyInterceptor">
</interceptor>
</interceptors>
<action name="myAction" class="com.MyAction">
<result name="success">/success.jsp</result>
<result name="input">/index.jsp</result>
<!-- 引用默认拦截器 -->
<interceptor-ref name="defaultStack"></interceptor-ref>
<!-- 引用自定义拦截器 -->
<interceptor-ref name="myInterceptor"></interceptor-ref>
</action>
</package>
</struts>
<!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" />
<include file="my.xml"></include>
</struts>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
</head>
<body>
<s:form method="post" action="myAction">
<s:textfield name="username" label="用户名"></s:textfield>
<s:password name="password1" label="密码"></s:password>
<s:password name="password2" label="确认密码"></s:password>
<s:submit value="注册"></s:submit>
</s:form>
</body>
</html>
pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<h3>注册成功</h3>
用户名:<s:property value="username"/><p>
密码: <s:property value="password1"/>
</body>
</html>
Action信息,正在执行Action....
2010-11-1 20:39:11 com.opensymphony.xwork2.util.logging.commons.CommonsLogger warn
警告: Could not find property [org.apache.catalina.jsp_file]
拦截器信息:Action执行完毕