Struts裡的html:Cancel標簽是在Form中經常運用的一個標簽
===========================
<html:cancel>
<bean:message key=
</html:cancel>
===========================
這個標簽將生成如下的HTML代碼
<input type=
bCancel=true是一段javascript
這段Javascript簡略摘要如下
===========================
<script type=
<!
var bCancel = false;
function validateCreateUserForm(form) {
if (bCancel)
return true;
else
return validateMaxLength(form) && validateRequired(form) && validateMinLength(form);
}
===========================
由上可以看到
沒有對這個Cancel動作寫特定代碼的話
type也等於submit)
這一點需要非常的注意!所以
===========================
// Was this transaction cancelled?
if (isCancelled(request)) {
return (mapping
}
===========================
有了以上的代碼
本來事情已經解決
OK
首先發現
===========================
/**
* <p>Returns <code>true</code> if the current form
* pressed
* request attribute has been set
* button generated by <strong>CancelTag</strong> was pressed by the user
* in the current request
* by an <strong>ActionForm</strong>
* will have been skipped by the controller servlet
*
* @param request The servlet request we are processing
* @see org
*/
protected boolean isCancelled(HttpServletRequest request) {
return (request
}
===========================
哦
Struts會在request對象中綁定一個對象
那Struts是在什麼地方綁定了這個對象呢?很自然的
從ActionServlet的process方法開始找起
===========================
/**
* <p>Process an <code>HttpServletRequest</code> and create the
* corresponding <code>HttpServletResponse</code>
*
* @param request The servlet request we are processing
* @param response The servlet response we are creating
*
* @exception IOException if an input/output error occurs
* @exception ServletException if a processing exception occurs
*/
public void process(HttpServletRequest request
HttpServletResponse response)
throws IOException
//省略代碼若干
// Process any ActionForm bean related to this request
ActionForm form = processActionForm(request
//答案就在這個processPopulate方法中
processPopulate(request
if (!processValidate(request
return;
}
/**
* Populate the properties of the specified ActionForm instance from
* the request parameters included with this request
* request attribute <code>Globals
* the request was submitted with a button created by
* <code>CancelTag</code>
*
* @param request The servlet request we are processing
* @param response The servlet response we are creating
* @param form The ActionForm instance we are populating
* @param mapping The ActionMapping we are using
*
* @exception ServletException if thrown by RequestUtils
*/
protected void processPopulate(HttpServletRequest request
HttpServletResponse response
ActionForm form
ActionMapping mapping)
throws ServletException {
if (form == null) {
return;
}
// Populate the bean properties of this ActionForm instance
if (log
log
}
form
form
if (mapping
request
mapping
}
RequestUtils
request);
// Set the cancellation request attribute if appropriate
if ((request
(request
request
}
}
===========================
OK
TRUE這個對象以Globals
至於這個Constants
中
<input type=
而Constants
From:http://tw.wingwit.com/Article/program/Java/ky/201311/28930.html