EASYUI+SPRINGMVC Pass Value

Source: Internet
Author: User

The whole structure of colleges and universities adopts springmvc+hibernate+easyui+mysql;

The project foreground frame uses Easyui, the first use of this framework or feel very good to get started, there are Chinese official website and there are a lot of well-done demo as a reference, basically we in the project development commonly used in the control on the official web can be found. In addition, help documents are available and can be downloaded on the official web site. The help document gives a specific method of each control, the event has been used, and also gives some simple small examples, basically simple.

Easyui Demo Chinese website address: http://www.jeasyui.net/demo/321.html

Easyui Help Documentation: http://download.csdn.net/detail/lypf19900912/8400833

So for Easyui learning, as long as there are some basic HTML and JS Foundation, learning is not difficult. This time in the project use Easyui think should summarize is the Easyui and backstage of the pass value, now the university one period has already come to an end, so in this gap on their own in the development process to master some of the value of the skills summed up.

1. The method of transmitting values provided in the Easyui control

Some controls in Easyui provide URL properties that allow direct access to the background and display the data that is passed in the background directly on the bound control, much like the data-bound control learned in learning ASP.

There are more tables and tree shapes and combo drop-down boxes used in the development of the project. The sample code for the table and combo box is as follows

Front desk

<% @page import= "com.tgb.itoo.assess.entity.CourseAssessResult"%><%@ page language= "java" contenttype= " text/html; Charset=utf-8 "pageencoding=" UTF-8 "%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >

For these properties (Url,method, etc.) can be directly written on the control, but I am more accustomed to writing in JS, or it will become a page on the control will be a large part of the overall look at the page will appear very messy, and then debugging the front of the code when the location is not good, debugging. (Personal habits, these attributes written on the control are also completely no problem)


Background

Using SPRINGMVC, so the URL written on the page is a method in the controller, there are two ways to accept the URL parameter in the background

1. Use the Request object to obtain

@RequestMapping (value= "/querydata") public void Querydata (httpservletrequest request,httpservletresponse response) Throws Exception {request.getparameter ("id"); SYSTEM.OUT.PRINTLN (ID);}

2. Add the parameters in the URL in the Controller method

@RequestMapping (value= "/querydata") public void Querydata (String id,httpservletrequest request,httpservletresponse Response) throws Exception {System.out.println (id);}


Two points to be aware of:

1 Easyui can only parse JSON strings, that is, data passed in the background if you want to bind to the Easyui control, you must convert the data to the form of a JSON string.

2 Pass-through is not just a code-passing URL, but also an important access parameter


2. jquery's Ajax Pass value

Although we used the foreground framework, we would definitely use Ajax if we wanted to implement some asynchronous calls. In fact, even if it is not asynchronous calls can be Ajax. Because AJAX access can handle the content in the URL. Here's a look at the parameters in jquery's Ajax values and a small example of how to use them.

Parameter description:

URL: The requested address is requested for a parameter of type string, (the current page address is assumed to be the default).

Type: A parameter of type string is required, and the request method (post or get) defaults to get. Note Other HTTP request methods, such as put and

Delete can also be used, but only some browsers support it.

Timeout: Requires a parameter of type number to set the request time-out (in milliseconds). This setting overrides the global setting of the $.ajaxsetup () method

Reset

Async: Requires a parameter of type Boolean, which is set to True by default and all requests are asynchronous requests.

If you need to send a synchronization request, set this option to false. Note that the sync request will lock the browser, and the user's other actions must wait

The request is complete before it can be executed.

Cache: A parameter that is required to be of type Boolean, which is true by default (False when datatype is a script).

Set to False to not load the request information from the browser cache.

Data: A parameter that is required to be an object or string that is sent to the server. Automatically converts to a string if it is not already a string

Expression The GET request will be appended to the URL. To prevent this automatic conversion, you can view the ProcessData option. The object must be a key/value grid

, for example {foo1: "Bar1", Foo2: "Bar2"} is converted to &FOO1=BAR1&FOO2=BAR2. If it is an array, jquery will automatically be a different

The value corresponds to the same name. For example {foo:["Bar1", "Bar2"]} is converted to &FOO=BAR1&FOO=BAR2.

DataType: A parameter of type string is required and the expected data type is returned by the server. If not specified, jquery is automatically mime based on the HTTP package

The information returns Responsexml or ResponseText, and is passed as a callback function parameter.

The following types are available:

XML: Returns an XML document that can be processed with jquery.

HTML: Returns plain text HTML information, and the included script tag is executed when the DOM is inserted.

Script: Returns plain text JavaScript code. Results are not automatically cached. Unless the cache parameter is set. Note in the remote request

(not under the same domain), all post requests are converted to get requests.

JSON: Returns the JSON data.

JSONP:JSONP format. When a function is called using the Sonp form, for example Myurl?callback=?,jquery will automatically replace the latter

“?” is the correct function name to execute the callback function.

Text: Returns a plain text string.

Beforesend: A function that requires a parameter of type function that can modify a XMLHttpRequest object before sending a request, such as adding a custom

HTTP headers. If you return False in Beforesend, you can cancel this Ajax request. The XMLHttpRequest object is the only parameter

Number.

function (XMLHttpRequest) {

This Options parameters passed when calling this Ajax request

}

Complete: A parameter that is required to be a function type, called when the request is completed (invoked when the request succeeds or fails).

Parameters: The XMLHttpRequest object and a string that describes the successful request type.

function (XMLHttpRequest, textstatus) {

This Options parameters passed when calling this Ajax request

}

Success: A callback function called after a successful request for a parameter of function type, with two parameters.

(1) The data returned by the server and processed according to the datatype parameter.

(2) A string describing the status.

function (data, textstatus) {

Data may be xmldoc, jsonobj, HTML, text, and so on

This Options parameters passed when calling this Ajax request

Error: A function that requires a parameter of type function, which is called when the request fails. The function has 3 parameters, that is, the XMLHttpRequest object, the wrong

Error message, and optionally, the wrong object to be captured.

The Ajax event functions are as follows:

function (XMLHttpRequest, textstatus, Errorthrown) {

Normally textstatus and Errorthrown only one of them contains information

This Options parameters passed when calling this Ajax request

}

More commonly used: Url,type,data,datatype,success,error

$.ajax ({<span style= "White-space:pre" ></span> type: "POST", url: ' querycoursebyteacher?teacherid= ' + Teacherid, Cache:false, DataType: "JSON", success:function (data) {$ ("#course"). ComboBox ("LoadData", data);});  

3. JavaScript Pass Value

In the JS code we are familiar with some of the access URL and the way to pass parameters.

JS can only directly access the URL, not the content in the URL processing, if you want to work with the content of the URL in the use of jquery Ajax method.

Window.location.href=url;



EASYUI+SPRINGMVC Pass Value

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.