首先到下載Struts
一個用戶注冊系統
項目建立
正式開發前
開發時
注冊頁面
<%@ page contentType=\
%>
<%@ taglib uri=\
%>
<%@ taglib uri=\
%>
<html:html locale=\
<head>
<title>RegUser</title>
<html:base/>
</head>
<body bgcolor=\
<html:errors/>
<html:form action=\
<table border=\
<tr>
<th align=\
Logname:
</th>
<td align=\
<html:text property=\
</td>
</tr>
<tr>
<th align=\
Password:
</th>
<td align=\
<html:password property=\
</td>
</tr>
<tr> [Page]
<th align=\
E
</th>
<td align=\
<html:password property=\
</td>
</tr>
<tr>
<td align=\
<html:submit property=\
</td>
<td align=\
<html:reset/>
</td>
</tr>
</table>
</html:form>
</body>
</html:html>
此JSP頁面不同於普通的JSP頁
Struts
<Struts
<form
<form
type=\
</form
<action
<action path=\
type=\
attribute=\
scope=\
validate=\
<forward name=\
<forward name=\
Struts的核心是Controller
FormBean
package org
import javax
import org
import org
public final class RegUserForm extends ActionForm{
private String logname;
private String password;
private String email;
public RegUserForm(){
logname = null;
password = null;
email = null;
}
public String getLogName() {
return this
}
public void setLogName(String logname) {
this
}
public void setPassWord(String password) { [Page]
this
}
public String getPassWord() {
return this
}
public void setEmail(String email) {
this
}
public String getEmail() {
return this
}
public void reset(ActionMapping mapping
{
logname = null;
password = null;
email = null;
}
}
每一個FormBean 都必須繼承ActionForm類
ActionBean
package org
import javax
import org
public final class RegUserAction extends Action
{
public ActionForward perform(ActionMapping mapping
ActionForm form
HttpServletResponse res)
{
String title = req
String password = req
String email = req
/*
取得用戶請求
*/
}
}
FormBean的產生是為了提供數據給ActionBean
Servlet的演變
在Struts中
優點
Struts跟Tomcat
除此之外
關於頁面導航
缺點
Taglib是Struts的一大優勢
Struts將MVC的Controller一分為三
Struts從產生到現在還不到半年
From:http://tw.wingwit.com/Article/program/Java/ky/201311/27876.html