Development ideas of ExtJS and Javaweb application

Source: Internet
Author: User

Recently, to do some applications based on ExtJS interface, here, summarize the main points. The title is based on Javaweb, but basically a variety of server-side languages are available. Use ExtJS do interface, nothing is to cancel the original many JSP files, instead of using ExtJS to access, but some places somewhat inconvenient, the following is my own problems and experience.

1. How many JSPs are appropriate? No special requirements, 2 can be, one is login, one is the system homepage. Login page generally need to compare fancy, make one page, page number to apply the style; The home page contains the main layout, function, and function by ExtJS. For some special pages, such as a page/activex control that requires a specific HTTP header, you can only use a single page to do it, and in ExtJS you use the HTML attribute in the panel to specify an iframe to load the page.

2. Get information about the logged-on user. This I use a server-side program to generate a MIME-type JavaScript page. Can be servlet/action and other things, and then on the homepage as a JS file to refer to. This does not need to use AJAX to server fetch, high efficiency of its running stability. If this information needs to be updated, such as the user modified their real name, can reload the server-side JS, I used the jquery $.getscript way to update, that is, the user modified their information successfully, call $.getscript (' Userdata.action ') this way.


3. Login timeout judgment. Here need 2 kinds of judgment: 1 is the user to refresh the main page, this is the normal filter to judge, timed out to jump back to the login page; 2 o'clock Ajax request time to judge timeout, of course, also use filter, but directly with JS can not get this information, need to add some processing, such as no timeout, Add a value of Sessionstatus=pass to Httpheader,

The code for the server-side filter might be:

public void DoFilter (ServletRequest request, servletresponse response, Filterchain chain) throws IOException, servletexception {sysutil.getcurrentuser (req); UserInfo CurrentUser = Sysutil.getcurrentuser (req);//Gets the object of the current user from the session if (CurrentUser! = null) {( HttpServletResponse) response). SetHeader ("Sessionstatus", "Pass");} Chain.dofilter (request, response);}

On the client side, capture with ExtJS Ajax events, for example:

Ext.Ajax.on (' Requestcomplete ', checkusersessionstatus, this);    function Checkusersessionstatus (conn,response,options) {//alert ("checkusersessionstatus")    // Ext re-encapsulates the response object if (Response.getresponseheader) {var sessionstatus = Response.getresponseheader ("Sessionstatus"); if (sessionstatus! = ' Pass ') {       alert ("Login timed out, re-enter System");       window.location = "login.jsp";}}    }

Use of 4.javascript closures. In the ordinary page can not be closed, because the page reference JS relatively few, useless JS file can not reference, to find a JS file content is relatively easy. And based on the ExtJS or other JS interface framework of the program, JS file certainly a lot of, and most of them need to be referenced on the System home page, which is likely to cause a difficult to find a function, it is not conducive to writing clear code. Therefore, we must use the closed package to separate the JS function within each function. For example, you can use projectname.modelname this way to subcontract, such as the creation of a user list of functions in Userinfo.js, this can be written:

var myproject.userinfo = {};//myproject should be defined in the main JS file, such as var MyProject = {}; MyProject.UserInfo.createUserList = function () {   //Create user list panel code ... }


Development ideas for ExtJS and javaweb applications

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.