JSP code
<script type="Text/javascript">$ (function () {initprovinces (); }); /** * Get list of provinces*/function Initprovinces () {$ ('#province'). empty (); $.ajax ({type:"POST", Url:basepath+"district/getprovinces.do", Success:function (data) {$.each (data, function (I, it) {$ ("<option value= '"+ It.id +"'/>"+ It.name +"<br>"). Click (function () {initcities (it.id); }). AppendTo ($ ('#province')); }); } }); } /** * Get city list*/function Initcities (Provinceid) {$ ('#city'). empty (); $.ajax ({type:"POST", Url:basepath+"district/getcities.do?province="+Provinceid, success:function (data) {$.each (data, function (I, it) {$ ( "<option value= '"+ It.id +"'/>"+ It.name +"<br>"). Click (function () {initcounties (it.id); }). AppendTo ($ ('#province')); }); } }); } /** * Get a list of counties*/function Initcounties (Cityid) {$ ('#county'). empty (); $.ajax ({type:"POST", Url:basepath+"district/getcounties.do?city="+Cityid, success:function (data) {$.each (data, function (I, it) {$ ("<option value= '"+ It.id +"'/>"+ It.name +"<br>"). AppendTo ($ ('#province')); }); } });}//...</script><body>Select region:<SelectId='Province'><option>---province---</option></Select> <SelectId=' City'><option>---City---</option></Select> <SelectId='County'><option>---area---</option></Select></body>Spring MVC Code: @Controller @requestmapping (Value="/district") Public classDistrictcontroller {@ResourcePrivateDistrictservice Districtservice;/** * Get province list * @return * @throws Exception*/@RequestMapping (Value="getprovinces") @ResponseBody PublicObject getprovinces () throws Exception {returndistrictservice.getprovinces ();} /** * Get city list * @param province * @return * @throws Exception*/@RequestMapping (Value="getcities") @ResponseBody PublicObject getcities (@RequestParam (value ="Province") String province) throws Exception {returndistrictservice.getcities ();} //the next level of access and GetCities methods are the same, so this is skipped}
Spring mvc+jsp achieves level three linkage