如果你經常去Servlet或JSP的新聞組或者郵件列表
簡單地說
Model I
如果是在一個人人都精通Java和HTML的環境中
在下面這個例子中
======================================================================
﹤xml version=
﹤H
﹤jsp:scriptlet﹥
//the parameter
TimeZone timeZone = TimeZone
if (request
{
String timeZoneArg = request
timeZone = TimeZone
// gets a TimeZone
// its a positive argument
}
//since we´re basing our time from GMT
Calendar myCalendar = Calendar
﹤/jsp:scriptlet﹥
﹤%= myCalendar
﹤%= myCalendar
﹤%= myCalendar
======================================================================
相應地
Model II: 重定向請求(Redirecting Requests)
在一個團隊開發環境中
現在我們可以使用Model II來表示Model I的那個例子
Controller: timeByZone
controller可以是一個servlet或一個JSP頁
======================================================================
﹤xml version=
﹤!
﹤jsp:scriptlet﹥
//the parameter
TimeZone timeZone = TimeZone
if (request
{
String timeZoneArg = request
timeZone = TimeZone
// gets a TimeZone
// its a positive argument
}
TimeBean timeBean = new TimeBean();
timeBean
timeBean
timeBean
HttpSession mySession = request
mySession
﹤/jsp:scriptlet﹥
﹤jsp:forward page=
======================================================================
View: displayTime
同樣地
======================================================================
﹤xml version=
﹤H
﹤jsp:useBean class=
﹤jsp:getProperty name=
﹤jsp:getProperty name=
﹤jsp:getProperty name=
﹤!
﹤jsp:scriptlet﹥
HttpSession mySession = request
TimeBean timeBean = mySession
if (timeBean != null)
{ // check to make sure its not null
out
out
out
out
out
}
else
{
out
}
﹤/jsp:scriptlet﹥
======================================================================
From:http://tw.wingwit.com/Article/program/Java/hx/201311/27100.html