How Java background configuration information is passed to the front-end JSP page

Source: Internet
Author: User

Requirements: The system front-end JSP uses the Easyui DataGrid to show some task information, a status message in the task information that shows the value is a number,

You need to display the status as descriptive information based on the mappings that are saved in the background.

The original JSP front-end display:

Solution, use the Create JSON data in the background, then pass it to the foreground JSP page, and use Eval to parse it to get a description of the value corresponding to the following operation:

1. Creating JSON data (Java)

    //Task List     Public Static FinalString task_pending = "0"; //command processing succeeded     Public Static FinalString task_command_success = "1"; //command processing failed     Public Static FinalString task_command_failed = "2"; //Download processed successfully     Public Static FinalString task_down_success = "3"; //Download processing failed     Public Static FinalString task_down_failed = "4"; //message sent successfully     Public Static FinalString task_mail_success = "5"; //message failed to send     Public Static FinalString task_mail_failed = "6"; //Processing Success     Public Static FinalString Task_complete = "99";  Public StaticString Getstatusjson () {jsonobject Statusjson=NewJsonobject (); Statusjson.put (task_pending,"Awaiting treatment"); Statusjson.put (task_command_success,"Script execution succeeded"); Statusjson.put (task_command_failed,"Script execution Failed"); Statusjson.put (task_down_success,"File Download succeeded"); Statusjson.put (task_down_failed,"File download Failed"); Statusjson.put (task_mail_success,"Mail sent successfully"); Statusjson.put (task_mail_failed,"Message sent Failed"); Statusjson.put (Task_complete,Complete); returnstatusjson.tostring (); }

2. Transfer value (Java)

String Statusjson = Constants.getstatusjson (); Resultmap.put ("Statusjson", Statusjson);

3. Use JS to get the value (JS) in the front-end JSP

// Get the status description based on the incoming status code function Getstatusdesc (key) {    var obj = eval ("(" + ' ${statusjson} ' + ")");     return Obj[key];}    

4. Calling function using the formatter of the DataGrid

1 { 2Field: ' Status ', 3Title: ' State ', 4HAlign: ' Left ',5Align: ' left ',6Width: ' 100 ',7Formatterfunction(value,row,index) {8         vardesc =Getstatusdesc (value);9         returndesc;Ten     } One},
View Code

The final results are as follows:

Something: The first is in the background using map as the value, JS in the resolution map is more complex, and later to use JSON more convenient.

How Java background configuration information is passed to the front-end JSP page

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.