Detailed code:
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >//JSON$ (document). Ready (function() { $(' #myForm '). Ajaxform ({//declares the type of data returned by the server.DataType: ' JSON ', Success:processjson}); }); functionProcessjson (data) {//' data ' is a JSON object that is returned from the server.$ (' #jsonOut '). HTML (data.name + "" +data.address + "" +data.comment); } //XML$ (document). Ready (function() { $(' #xmlForm '). Ajaxform ({//declares the type of data returned by the server.DataType: ' xml ', success:processxml}); }); functionProcessxml (responsexml) {//' Responsexml ' is an XML document that is returned from the server. varName = $ (' name ', Responsexml). text (); varAddress = $ (' address ', Responsexml). text (); varComment = $ (' comment ', Responsexml). text (); $(' #xmlOut '). HTML (name + "+address +" +comment); } //HTML$ (document). Ready (function() { $(' #htmlForm '). Ajaxform ({//updates the contents of the ID htmlcssrain with the data returned by the server.Target: ' #htmlOut ', Success:function() { $(' #htmlOut '). FadeIn (' slow ')); } }); }); </script> Name:<input type= "text" name= "name" id= "name"/> <br/>Address:<input type= "text" name= "Address" id= "Address"/><br/>Self Introduction:<textarea name= "comment" id= "comment" ></textarea> <br/> <input type= "Submit" id= "Test" va Lue= "json way back"/> <br/> <div id= "Jsonout" ></div> </form> <!--Demo2 xml--> Name:<input type= "text" name= "XMLName" id= "XMLName"/> <br/>Address:<input type= "text" name= "xmladdress" id= "xmladdress"/><br/>Self Introduction:<textarea name= "xmlcomment" id= "xmlcomment" ></textarea> <br/> <input type= "Submit" id= "XM Ltest "value=" xml return "/> <br/> <div id=" Xmlout "></div> </form> <!--Demo3 html--> Name:<input type= "text" name= "HTMLName" id= "HTMLName"/> <br/>Address:<input type= "text" name= "htmladdress" id= "htmladdress"/><br/>Self Introduction:<textarea name= "htmlcomment" id= "htmlcomment" ></textarea> <br/> <input type= "Submit" id= " Htmltest "value=" html return "/> <br/> <div id=" htmlout "></div> </form> </b Ody>New json.jsp File:
<%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8"%><%request.setcharacterencoding ( "UTF-8"); // Prevent garbled! String name = Request.getparameter ("name"= Request.getparameter ("address"= Request.getparameter (" Comment "+"-"+address +"-"+" {name: ' "+name+" ', Address: ' "+address+" ', Comment: ' "+comment+" '} " ); %>
New xml.jsp File:
<%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8"%><%request.setcharacterencoding ("UTF-8");//Prevent garbled!String name = Request.getparameter ("XMLName"); String Address= Request.getparameter ("xmladdress"); String Comment= Request.getparameter ("Xmlcomment"); SYSTEM.OUT.PRINTLN (Name+ "-" +address + "-" +comment); Response.setcontenttype ("Text/xml");//Note that since you are passing in XML, it must be written here. Out.print ("<?xml version=\" 1.0\ "encoding=\" utf-8\ "?>"); Out.print ("<root>"); Out.print ("<name>" +name+ "</name>"); Out.print ("<address>" +address+ "</address>"); Out.print ("<comment>" +comment+ "</comment>"); Out.print ("</root>");%>
Create a new html.jsp file:
<%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8"%><%request.setcharacterencoding ( "UTF-8"); // Prevent garbled! String name = Request.getparameter ("htmlname"= Request.getparameter ("htmladdress"= Request.getparameter ("htmlcomment"+ "-" +address + "-" +"<div style= ' Background-color: #ffa; padding:20px ' > "+name+" "+address+" " +comment+" </div> " ); %>
Use of the JQuery form plugin--processing the JSON returned by the server, xml,html data