SPRINGMVC Project encountered to use the Jqueryajax to the foreground to pass the dynamic table needs, the original practice is to receive data in JS and then splicing into a table and then to the JSP display, later on this foreign site saw the following use of the "template" design, feel very reasonable, I tested a bit , think more than before JS splicing easy to use a lot, greatly reduce the pressure of JS. I just copied the original author's answer (the answer is really detailed), record it, feel that I grew up again.
Mycontroller.java
@Controllerpublic class MyController { @RequestMapping ( method= Requestmethod.get, value= "/mainview" ) public ModelAndView Getmainview ( ... ) { /* do all your normal stuff here to build your primary non-ajax view * in the same way you always do */ } /* this is the conroller ' s part of the magic; i ' m just using a simple get but you * could just as easily do a post here, obviously */ @RequestMapping ( method=requestmethod, value= "/subview" ) public Modelandview getsubview ( Model model ) { model.addattribute ( "User", "joe dirt" ); model.addattribute ( "Time", new date () ); return new modelandview ( "SubView" ); }}
mainview.jsp
(...) <script src= "Http://code.jquery.com/jquery-1.7.1.min.js" ></script><script type= "text/ JavaScript "> function doajaxpost () { $.ajax ({ type: "GET", url: "SubView", success: function (response) { $ ("#subViewDiv"). HTML ( response ); } }); }</script><input type= "button" value= "Go!" onclick= "Doajaxpost ();" /><div id= "Subviewdiv" ></div> (...)
subview.jsp
(...)
Here is the original address:
Http://stackoverflow.com/questions/4816080/how-to-render-a-view-using-ajax-in-spring-mvc
Thank the Great God! And thanks to my great far elder brother!
This article is from the "Java Program Ape Blog" blog, be sure to keep this source http://chengxuyuan.blog.51cto.com/5789198/1598960
jquery Ajax transfer view in Spring MVC