AJAX = asynchronous JavaScript and XML.
AJAX is a technique for creating fast, Dynamic Web pages.
AJAX enables Web pages to be updated asynchronously by exchanging small amounts of data in the background with the server. This means that you can update a part of a webpage without reloading the entire page.
Traditional Web pages (without AJAX) if you need to update the content, you must reload the entire page surface.
You can use jquery's Ajax to interact with Java via post
The implementation code sample is as follows:
HTML code
<Body> <DivID= "Main"> <ButtonID= "Mybut">Ajax Get Data</Button> <DivID= "Container"></Div> </Div></Body>
Style code
<styletype= "Text/css">#main{margin:0 Auto;width:400px;}#container{width:400px;Height:300px;Border:1px dashed #666;text-align:Center;Line-height:300px;}</style>
Javastript Code
<script type= "Text/javascript" src= "js/jquery-1.8.3.js" ></script><script type= "Text/javascript" > $(function() { $(' #myBut '). Click (function() {$.post ("Jqueryajaxservlet", {age:18, Name:"Zhang" }, function(data, textstatus) {varContainer = $ (' #container '); varResultdata =$.parsejson (data); varAge =Resultdata.age; varName =Resultdata.name; Container.html ("Name:" + name + "," + "Age:" +Age ); }); }); });</script>
Java code
Public class Jqueryajaxservlet extends HttpServlet { void doget (httpservletrequest request, HttpServletResponse response) throws Servletexception, IOException { = Request.getparameter ("Age") ; = Request.getparameter ("name"); = "{\" name "+" \ ": \" "+ name +" \ "," + "\" Age " +" \ ":" + Age + "}"; System.out.println (Personjson); Response.getwriter (). write (Personjson); } void DoPost (httpservletrequest request, httpservletresponse response) throws Servletexception, IOException { doget (request, response);} }
Web. XML code
<servlet> <Servlet-name>Jqueryajaxservlet</Servlet-name> <Servlet-class>Com.jquery.ajax.com.JqueryAjaxServlet</Servlet-class> </servlet> <servlet-mapping> <Servlet-name>Jqueryajaxservlet</Servlet-name> <Url-pattern>/jqueryajaxservlet</Url-pattern> </servlet-mapping> <welcome-file-list> <Welcome-file>index.jsp</Welcome-file> </welcome-file-list>
Another implementation code is attached:
Ajax calls the example of a background Java class blog.csdn.net/rznice/article/details/43561645
Java + jquery + ajax + JSON interactive http://yangchunhe.iteye.com/blog/1751239
Ajax Interactive Method implementation