Spring提供了DelegatingActionProxy類
<%@page contentType=
<html>
<head>
<title>實現用戶登錄的Struts實例</title>
</head>
<body>
<font size=
<form name=
method=
用戶名
<input type=
<br>
密碼
<input type=
<br>
<input type=
</form>
</body>
</html>
package com
import org
publicclass User extends ActionForm {
private String username=null;
private String password=null;
public String getUsername() {
returnusername;
}
publicvoid setUsername(String username) {
this
}
public String getPassword() {
returnpassword;
}
publicvoid setPassword(String password) {
this
}
}
package com
import javax
import javax
import org
import org
import org
import org
import com
import com
publicclass LoginDelegatingActionProxy extends Action {
private Login login;
public Login getLogin() {
returnlogin;
}
publicvoid setLogin(Login login) {
this
}
public ActionForward execute(ActionMapping mapping
HttpServletRequest request
throws Exception {
String forwardJsp =
getLogin()
request
request
return mapping
}
}
package com
import com
publicinterface Login {
publicabstractvoid login(User user);
publicabstract String getMsg();
}
package com
import com
import com
publicclass LoginImpl implements Login {
private String msg;
public String getMsg() {
returnthis
}
publicvoid login(User user) {
String username = user
String password = user
if (username == null && password == null) {
msg =
} elseif (
msg =
} elseif (
msg =
} elseif (!
msg =
}
}
}
<?xml version=
<!DOCTYPE struts
<struts
<!
<form
<form
type=
<form
</form
<action
<action path=
type=
name=
<forward name=
path=
</forward>
</action>
<action path=
type=
parameter=
</action>
</action
<plug
className=
<set
value=
</plug
</struts
<?xml version=
<!DOCTYPE beans PUBLIC
<beans>
<bean id=
</bean>
<!
<bean name=
<property name=
<ref bean=
</property>
</bean>
</beans>
From:http://tw.wingwit.com/Article/program/Java/ky/201311/28945.html