Ajax remote script calling engine with a performance improvement of 10 times

Source: Internet
Author: User

Easyjweb already has an Ajax remote script calling engine, which is very early. However, due to some performance problems, we have not recommended them until the latest m3 release. By improving the Ajax remote script calling engine, we can simplify the process of returning complex objects, through tests in several previous applications, we found that the performance was improved by at least 10 times at once and the operation was stable. Therefore, we recommend it to you here.

Online example: http://easyjweb.demo.easyjf.com/ajax/ajax.html

Download the complete sample application and source code: ftp://ftp1.easyjf.com/easyjweb/demo/ajax.war

Easyjweb is a framework that provides support for Ajax remote script calling. It helps you complete most of the details in Ajax remote script calling, basically, you can easily use JavaScript to call the related methods of server service components without writing additional code. These service components can be any Java object, for example, beans in ejbs, easyjweb windows, and beans in spring containers. The following steps are required to use easyjweb's Ajax remote script call:
1. Configure the business components for client script calls in the easyjweb container or sub-container. For example, in the easyjweb configuration file, configure the bean as follows:

<Bean name = "personservice" class = "easyjweb. Demo. Service. impl. personserviceimpl"/>

The code for personserviceimpl. Java is as follows:

Package easyjweb. Demo. Service. impl;

Import java. util. date;
Import java. util. List;
Import java. util. Map;

Public class personserviceimpl ...{
/***//**
* Get the current server time
* @ Return
*/
Public date gettime ()...{
Return new date ();
}}

2. In the easyjweb configuration file, configure the business components and methods in the container to be exposed to the client for remote script calls. The content is roughly as follows:

<Ajax>
<Services allowname = "*">
<Service name = "personservice"/>
</Services>
</Ajax>

The above Ajax configuration information indicates all the public methods of the violent personservice for the client to use JavaScript to call.
The above two steps are required to complete the work on the server side. The server no longer needs to write any action. easyjweb will automatically process Ajax remote script calls sent by the client. Next let's look at the client program.
3. In order to directly use JavaScript to call the Ajax remote script of the personservice service component on the client page, we need to introduce the following three JavaScript codes on the page.

<SCRIPT src = "EJF/easyajax/prototype. js" type = "text/JavaScript"> </SCRIPT>
<SCRIPT src = "EJF/easyajax/engine. js" type = "text/JavaScript"> </SCRIPT>
<SCRIPT src = "EJF/easyajax/personservice. js" type = "text/JavaScript"> </SCRIPT>

The first EJF/easyajax/prototype. javascript introduces prototype. JS, a basic JavaScript library that provides many extensions to basic JavaScript classes and provides Ajax-related practical components. The easyjweb remote script calling engine is based on prototype. built in Js.
The second EJF/easyajax/engine. JS is the remote script calling support engine of easyjweb. It is responsible for processing details related to Ajax remote script calling, such as parameter processing and callback processing, some practical tools, such as easyajaxutil, are provided for the client.
The third EJF/easyajax/personservice. JS is a personservice object. The content of personservice. JS is generated based on the bean named personservice in the container on the server and the Ajax configuration information of easyjweb. As long as personservice. JS is introduced, we can directly call the related methods of personservice on the page.
The above three JS files are dynamically generated on the server. We need to submit all/EJF/* URLs to easyjweb in the web. xml file for processing. Therefore, add the following ing content to the URL of Web. xml:

<Servlet-mapping>
<Servlet-Name> easyjf </servlet-Name>
<URL-pattern>/EJF/* </url-pattern> <! -- All URLs starting with/EJF/are processed by easyjweb -->
</Servlet-mapping>

4. Use JavaScript to call server-related methods on the page

<SCRIPT>...
Function showservertime ()...{
Personservice. gettime (Showtime );
Function Showtime (RET )...{
Alert ("server end time:" + RET );
}
}
</SCRIPT>

Everything is so simple, you don't need to write any personservice code, you don't need to write any action, you just need to perform very simple configuration, the service components on our server can support Ajax remote script calls.

Related Article

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.