Ajax is a very powerful thing, before written an Ajax servlet asynchronous interaction, is placed on the URL of the request to implement, placed on the URL is limited in length, if you want to save a long thing, such as blog this is not!
Guide Package:
The main is Json.jar this bag, the other is Ueditor bag!
Front Code: (This is part of the main code, omitting the Ueditor code)
//Introduce some plugins for Easyui<Linkrel= "stylesheet"type= "Text/css"href= "Jquery-easyui-1.3.3/themes/default/easyui.css"><Linkrel= "stylesheet"type= "Text/css"href= "Jquery-easyui-1.3.3/themes/icon.css"><Scripttype= "Text/javascript"src= "Jquery-easyui-1.3.3/jquery.min.js"></Script><Scripttype= "Text/javascript"src= "Jquery-easyui-1.3.3/jquery.easyui.min.js"></Script><Scripttype= "Text/javascript"src= "Jquery-easyui-1.3.3/locale/easyui-lang-zh_cn.js"></Script>the method of submitting the Content function submitcontents () {//ue.geteditor (' editor '). GetContent () This method is the method that the Ueditor gives to get the input box content, realizes some var contents = ue.geteditor (' editor '). GetContent ();
This is a jquery encapsulated Ajax method.
Save.do is the back office address! {Text:contents} The previous one is the key, the latter is the value, from the background with GetParam ... method to get the value! function (result) is a handler that puts something back in the foreground.
Result is a JSON object returned in the background
$.post ("Save.do", {text:contents},function (result) {
if (result.success) { $.messager.alert (' System tip ', ' Operation succeeded! This is what is returned from the background: ' +result.contents '; } else{ $.messager.alert (' System tip ', ' Operation not successful! ');}} , "json");} Button Binding method <type= "button" value= "Commit" OnClick= "submitcontents ()">
Background code:
PackageCom.loger.servlet;Importjava.io.IOException;ImportJava.net.URLDecoder;Importjavax.servlet.ServletException;ImportJavax.servlet.http.HttpServlet;Importjavax.servlet.http.HttpServletRequest;ImportJavax.servlet.http.HttpServletResponse;ImportOrg.json.JSONObject; Public classSaveextendsHttpServlet {@SuppressWarnings ("Deprecation") @Overrideprotected voidDoPost (httpservletrequest req, HttpServletResponse resp)throwsservletexception, IOException {//TODO auto-generated Method Stub
The returned encoding filter, otherwise the reception of the Chinese will be garbled resp.setcharacterencoding ("Utf-8"); String Contents= Req.getparameter ("text");
Defines a JSON object, which is the jsonobject result of the value stored by a key-value pair=NewJsonobject (); if(contents = =NULL) {Result.put ("False",false ); System.out.println ("No content"); }Else{result.put ("Success",true); Result.put ("Contents", contents); SYSTEM.OUT.PRINTLN (contents); } resp.getwriter (). println (Result.tostring ()); } @Overrideprotected voidDoget (httpservletrequest req, HttpServletResponse resp)throwsservletexception, IOException {//TODO auto-generated Method Stub This. DoPost (req, resp); }}
Operation Result:
Jquery AJAX Simple implementation of front-end background data transfer