Struts里的html:Can
Struts里的html:Cancel标签是在Form中经常运用的一个标签,主要功能就是cancel当前Form,一般写法如下: =========================== =========================== 这个标签将生成如下的HTML代码: bCancel=true是一段javascript,bCancel是在使用Struts的Validator时,Struts自动为我们加的一段Javascript代码里的一个变量 这段Javascript简略摘要如下: =========================== ...全部
Struts里的html:Cancel标签是在Form中经常运用的一个标签,主要功能就是cancel当前Form,一般写法如下: =========================== =========================== 这个标签将生成如下的HTML代码: bCancel=true是一段javascript,bCancel是在使用Struts的Validator时,Struts自动为我们加的一段Javascript代码里的一个变量 这段Javascript简略摘要如下: =========================== true if the current form's cancel button was * pressed。
This method will check if the Globals。CANCEL_KEY * request attribute has been set, which normally occurs if the cancel * button generated by CancelTag was pressed by the user * in the current request。
If true, validation performed * by an ActionForm's validate() method * will have been skipped by the controller servlet。
* * @param request The servlet request we are processing * @see org。apache。struts。taglib。html。
CancelTag */ protected boolean isCancelled(HttpServletRequest request) { return (request。getAttribute(Globals。
CANCEL_KEY) != null); } =========================== 哦,原来是在request对象中查找Globals。CANCEL_KEY这个key值是否绑定了一个对象,如果是,那么就代表按下Cancel按钮后, Struts会在request对象中绑定一个对象,并以这个key值来命名 那Struts是在什么地方绑定了这个对象呢?很自然的,让我们从头找起 从ActionServlet的process方法开始找起,历经多次方法调用,终于找到了根源,原来是在RequestProcessor。
java中,代码如下: =========================== /** *
Process an HttpServletRequest and create the * corresponding HttpServletResponse。
* * @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, ServletException { //省略代码若干 // Process any ActionForm bean related to this request ActionForm form = processActionForm(request, response, mapping); //答案就在这个processPopulate方法中 processPopulate(request, response, form, mapping); if (!processValidate(request, response, form, mapping)) { return; } /** * Populate the properties of the specified ActionForm instance from * the request parameters included with this request。
In addition, * request attribute Globals。CANCEL_KEY will be set if * the request was submitted with a button created by * CancelTag。
* * @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。
populate() */ 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。
isDebugEnabled()) { log。debug(" Populating bean properties from this request"); } form。setServlet(this。
servlet); form。reset(mapping, request); if (mapping。getMultipartClass() != null) { request。
setAttribute(Globals。MULTIPART_KEY, mapping。getMultipartClass()); } RequestUtils。populate(form, mapping。
getPrefix(), mapping。getSuffix(), request); // Set the cancellation request attribute if appropriate if ((request。
getParameter(Constants。CANCEL_PROPERTY) != null) || (request。getParameter(Constants。CANCEL_PROPERTY_X) != null)) { request。
setAttribute(Globals。CANCEL_KEY, Boolean。TRUE); } } =========================== OK,看最后几行代码,Struts从request中取得Constants。
CANCEL_PROPERTY这个参数,如果这个参数不为空,那么他就将 TRUE这个对象以Globals。CANCEL_KEY为key值,放到了request对象中 至于这个Constants。
CANCEL_PROPERTY这个值是什么,现在都可以猜到了,显然就是html:Cancel这个标签生成的HTML代码 中,Cancel这个按钮的名称嘛!查了一下,果然是: 而Constants。
CANCEL_PROPERTY这个值就是org。apache。struts。taglib。html。CANCEL 。收起