Wmframework growth diary (2) -- v1.0jsp request data processing

Source: Internet
Author: User
This articleArticleIt has been deposited in the draft box for a long time and has been said to write it, but it is always occupied by other things. My current rest time is graffiti. I haven't organized wmframework for a long time, and I feel a little new to it. Today, I found this is the only thing left in the draft box. Let's write it. Here I will mainly introduce the jsp request data processing in wmframework version 1.0. This version is used in my school affairs management system, as described in the general process and (1, if you are interested, you can look back. It takes about two and a half years to complete wmframework V1.0. Of course, this is more due to the final adoption of this technical framework by the project team. With more users, the problems naturally exposed will gradually increase. In order to meet the general and flexible features, and solve the various needs that I did not consider before, I made a lot of modifications and improvements. After the project is completed, the final version 1.0 is stable. Let me first talk about What wmframework advocates. It mainly advocates the layering of development. You can find the answer in my "system development with WM framework for MVC team combination mode. For the development of a single module or function point, wmframework proposes that multiple JSP page requests share an action, a service external interface, and a Dao for processing. Therefore, wmframework is used, in general, developers do not need to write actions, services, and Dao, because the wmframework built-in public definitions have completed your operations. Without saying anything else, how much unnecessary resource overhead can be saved, and the developer's workload can be reduced directly and effectively. Why not? Wmframework mainly relies on AJAX data submission mode. In 1.0, it mainly uses synchronous request submission. Below I will specifically describe the front-end and back-end jsp request data processing. 1. Foreground Data encapsulation Wmframework requires developers to use HTML tags, some jstl tags, and custom tags in JSP. Generally, MVC tags similar to struts or spring are not recommended, because these labels are a JavaBean, if you use too many, it will inevitably increase the page load and request loading speed of JSP, such as directly using HTML tags, at least the parsing process of those MVC labels can be reduced. The following describes how to write a form element in JSP:

 

     input   type  =" text "  issave  =" true "  fieldname  =" useraccount "  require  =" true "  datatype  =" chars "  
showmessage =" the user account is empty or set incorrectly " maxlength =" 20 " class =" textfile " id = 'unit _ account' />

 

 

Here, wmframework extends HTML tags and adds several custom attributes. Issave = "true" indicates that the current form element must be submitted to the background for operations; fieldname indicates the name of an attribute matching the current form submission domain (or pojo; require indicates whether the current field is required. datatype indicates the data type to be filled in for the current element. Here chars indicates that the character type is required. showmessage indicates that the verification fails if the current form element does not pass. A prompt is required. Of course, not only can input be defined like this, as long as HTML supports page tags such as select, textarea, image, Div, TR, TD, and so on, these attributes can be defined, I will not list them here. 2. Front-end data verification After page elements are defined, the following is the front-end JS verification problem before the form submits data. Here, wmframework completes the verification through the custom JS object wmvalidate. In general, it is not recommended to directly call the method in wmvalidate, because wmvalidate is called to complete data verification, other objects are loading the form data. 3. Front-end data submission For the current JSP form data validation and loading process, it is mainly completed in the front-end JS entry object wmaction, so generally the page mainly calls wmaction. The following is an example of JSP calling wmaction object: This is an onclick event processing function triggered by the submit button. Code

  Function  Dosave (){
VaR AC = New Action (); // Create a JS object request action object
AC. setform (document. Forms [ 0 ]); // Set the form object of the data submitted this time. When a page contains too many elements or the form is, it can effectively reduce unnecessary page element columns.
AC. seturl (CPS + ' /Useraction. do? Action = add ' ); // Set the URL of the submitted path. CPS is the global variable defined in the public file, var cps = "<% = request. getcontextpath () %>"; that is, JS reference of the current context.
AC. settextdiv ( ' Textdiv ' ); // Set the ID of the DIV where the button is located. After the data is submitted, the current operation button will be hidden to prevent the user from clicking the button again.
AC. sethitdiv ( ' Hitdiv ' ); // Sets the ID of the DIV where the progress bar is located during asynchronous submission. During data processing, the submit button is hidden and a progress bar is displayed at the same position to identify the progress of the current request processing.
AC. setisasy ( True ); // Set the operation method for this submission: True asynchronous mode, that is, the current submission does not need to wait for a response from response, and can be completed in a way similar to the simultaneous processing of multiple threads on the CPU. False synchronous Mode means that after the current request is submitted, wait for the response from response. This is like an exclusive lock in the database. At the moment, only one request can be processed.
AC. setfunctionname ( " Insertuser " ); // Set the id value of the XML Node Method in the sqlmap configuration file submitted and executed this time. It is case sensitive. If you know ibatis, you should know what it refers.
AC. setdomainname ( " OA user " ); // Set the name of the encapsulated object for this submission (the name is the same as that for the background domain. You do not need to add the full path of the class, but it does not matter). The background will add and match the full path of the current domain object, this requires that the domain of the entire system is stored in a fixed package. Of course, if you really don't want to, add the package path of the current domain directly, such as AC. setdomainname ("com. test. oauser ");.
Ac.exe cute (); // Send data requests, because only simple save or delete operations are considered here, so no callback function is added for processing.
}

 

If you feel that the previous definition is too cumbersome and difficult to remember, you can use the second method to directly obtain the strings in XML format encapsulated by the data form, all data requests of wmframework are encapsulated in XML format and sent through Ajax. I have introduced this in (1. A definition reference is provided. Code

  Function  Dosave (){
VaR AC = New Action (); // Create a JS object request action object
AC. setform (document. Forms [ 0 ]); // Set the form object of the data submitted this time. It must be set here. Otherwise, wmvalidate cannot help you with data verification.
AC. seturl (CPS + ' /Useraction. do? Action = add ' ); // Same as above
AC. settextdiv ( ' Textdiv ' ); // Same as above
AC. sethitdiv ( ' Hitdiv ' ); // Same as above
AC. setisasy ( True ); // Set the operation method for this submission: True asynchronous mode false synchronous Mode
VaR Xmlstr = " <? XML version = \ " 1.0 \ " Encoding = \ " UTF - 8 \ " ?> "
+ " <Root> "
+ " <Vos id = " OA user " > "
+ " <VO> "
+ " <Username> test user </username> "
+ " <Useraccount> demo </useraccount> "
+ " & Lt; password & gt; 123 & lt;/password & gt; "
+ " <Usertype> 1 </usertype> "
+ " <Shortmentid> 1 </shortmentid> "
+ " <Function> insertuser </function> "
+ " </Vo> "
+ " </Vos> "
+ " </Root> " ;
AC. setxmlstr (xmlstr ); // Set the XML string of the request data
Ac.exe cute (); // Same as above
}

 

In this case, you can simply set it to submit and save the form data of the current JSP page. Of course, the settings here are too simple. In fact, you can also define the callback function here, operation Failure handler, operation success handler, debugging tracker, etc. However, such definition in v1.o only supports synchronous submission mode in this operation. That is, AC. setisasy (false ). After wmaction.exe cute () is executed, wmvalidate will be called for data verification. Of course, you can also skip the verification, so do not set the above form parameter, however, the method only supports data submission in the second way. If wmvalidate is verified, the current user determines which method is used to reprint the data. For example, the first method, the wmdataemun object is called to encapsulate the enumerated type of the submitted data form (this object has been deprecated in V2.0), that is, the form data is reproduced in A js-defined enumerated object, this process is completed in wmdocobject for unified XML string splicing and reading. If the user uses the second definition method, it will directly go to the wmservice object without passing through the above two objects, construct the XMLHTTPRequest object in wmservice and send the data through the send method. Here is a flowchart. At this point, the JSP front-end request processing process has basically ended, and the process may seem simple. It is really easy, because the wmframework is simple, but the relative processing of Version 2.0 is more complicated than this, and there are more compatible things, but for Small and Medium web application development, this is basically enough. Write it here first, and continue next time. Too many people are dazzled and it is not good to get indigestion... (Note: All my articles are original articles. Please indicate the source for reprinting! 20100616 is written in Shenzhen .)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.