Unveiling the default URL ing converter in easyjweb

Source: Internet
Author: User

In easyjweb's support for Ajax, reference is similar to <SCRIPT type = 'text/JavaScript 'src = 'ejf/easyajax/userservice. the javascript '> </SCRIPT> URL dynamically obtains the Javascript script that calls the service components on the server. In addition, you can use a URL similar to http: // localhost: 8080/user/edit/3 to edit a record in the crud Application Based on easyjweb. In easyjweb, how does one deal with these URLs? This article will make a simple analysis!
In easyjweb, there is a URL ing processor. By configuring this ing processor, you can easily implement requirements similar to urlrewrite in Web applications. The ing processor code is as follows:

Public interface ipathmappingruler ...{
// Parse the Request Path;
Public String getmodulename (); // obtain the Template Name.
Public map getparams (); // obtain the default template parameter.
Public String getcommand (); // get the template command
}

The default implementation of this interface is com. easyjf. Web. Core. pathmappingrulerimpl. In easyjweb-based applications, each request URL processed by the easyjweb framework is converted using this ing processor. By using easyjweb default URL ing converter, the client request path/module/command/Params is mapped according to the following request rules.
URL before Map Processing:
1./module/command/name = xxx
2./Module
3./module/command
4./module/command/12345
5./module/edit/12345/Title = 1111
6./moduel/Title = test

URL for ing:
1 ~ /Module. EJF? Easyjwebcommand = command & name = xxx
2 ~ /Module. EJF
3 ~ /Module. EJF? Easyjwebcommand = command
4 ~ /Module. EJF? Easyjwebcommand = command & cid = 1234
5./module. EJF? Easyjwebcommand = edit & cid = 123455 & Title = 111
6./module. EJF? Title = test

Therefore, in a crud application automatically generated by easyjweb, http: // localhost: 8080/user. EJF? The URL easyjwebcommand = edit & cid = 3 indicates editing the information of CID 3 in the user object. With the default ing rules, the above URL can be changed to the following format:

Http: // localhost: 8080/user/edit/3

This URL indicates that the user. EJF module is run. The sent command is edit and the standard key value is 3.

One of the most typical examples of the URL ing converter is the remote web script processing support engine, that is, part of Ajax functionality, which began to be added in the EasyJWeb-0.8 version. Remote JS script calls support only a small plug-in easyjweb. The Ajax Implementation of easyjweb is just a common easyjweb module (action ). This action is com. easyjf. Web. Ajax. ajaxengineaction.

Anyone who has read the article "easily develop Ajax applications in easyjweb" knows that remote web script calling involves a javascript stub problem about how to generate a method to call the server. In easyjweb's support for Ajax, you can use the following URL to generate a remote JavaScript call script.

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

The first statement returns the prototype. js script, the second statement returns the Ajax support engine. js script of easyjweb, and the third statement returns the remote call script that generates the server's userservice component.
The above URL is referenced through the native easyjweb URL and can be written in the following form:

<SCRIPT type = 'text/JavaScript 'src = "easyajax. EJF? Easyjwebcommand = prototype. js "> </SCRIPT>
<SCRIPT type = 'text/JavaScript 'src = 'easyajax. EJF? Engine. js'> </SCRIPT>
<SCRIPT type = 'text/JavaScript 'src = 'easyajax. EJF? Easyjwebcommand = userservice '> </SCRIPT>

The following code processes these calls in ajaxengineaction:

Public page doengine (webform form, module) throws exception ...{
Return Module. findpage ("engine-js ");
}

Public page doprototype (webform form, module) throws exception ...{
Return Module. findpage ("prototype ");
}

Public page doajaxhome (webform form, module) throws exception ...{
String command = commutil. null2string (Form. Get ("easyjwebcommand "));
If (command. endswith (". js "))
...{
Command = command. substring (0, command. Length ()-3 );
}
Object bean = ajaxutil. getservicecontainer (). getservice (command );
// System. Out. println (command );
Form. addresult ("scriptname", command );
Form. addresult ("methodlist", ajaxutil. getajaxstub (bean ));
Return Module. findpage ("stub ");
}

Summary:
A simple and applicable web MVC framework not only implements simple page and code separation functions, but also provides more practical tools related to web applications and Abstract Functions for solving general application requirements. In easyjweb, in addition to having many basic features of the MVC Framework, easyjweb also has many built-in tools to meet the needs of Application Web applications, for example, URL ing, automatic code generation, and permission system support make Web Application Development easier and more efficient. As a web MCX framework fully initiated and implemented by domestic Java open source enthusiasts, although there are still many problems in the EasyJWeb-0.8 version, but as long as more open source enthusiasts to participate in it, I believe that it will be improved in future versions.

(Author:Easyjf Open SourceDaxiaYou are welcome to repost it. Please keep the author's statement for reprinting. Thank you !)

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.