Use of the jQuery form plugin -- Process JSON, XML, HTML data returned by the server, and jqueryjson
Code details:
<! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN">
Create a json. jsp file:
<% @ Page language = "java" import = "java. util. * "pageEncoding =" UTF-8 "%> <% request. setCharacterEncoding ("UTF-8"); // prevents garbled! String name = request. getParameter ("name"); String address = request. getParameter ("address"); String comment = request. getParameter ("comment"); System. out. println (name + "-" + address + "-" + comment); out. println ("{name: '" + name + "', address: '" + address + "', comment: '" + comment + "'}"); %>
Create an xml. jsp file:
<% @ Page language = "java" import = "java. util. * "pageEncoding =" UTF-8 "%> <% request. setCharacterEncoding ("UTF-8"); // prevents 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 because you are passed in xml format, 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 an html. jsp file:
<% @ Page language = "java" import = "java. util. * "pageEncoding =" UTF-8 "%> <% request. setCharacterEncoding ("UTF-8"); // prevents garbled! String name = request. getParameter ("htmlname"); String address = request. getParameter ("htmladdress"); String comment = request. getParameter ("htmlcomment"); System. out. println (name + "-" + address + "-" + comment); out. println ("<div style = 'background-color: # ffa; padding: 20px '> "+ name +" "+ address +" "+ comment +" </div> "); %>