//以下屬性信息都是從前臺(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執行完畢