이 애플릿의 기능은 주로 데이터베이스에서 지방, 도시 및 지구 정보를 검색하고 비동기 요청을 사용하여 드롭 다운 목록에 표시하는 것입니다.
코드는 다음과 같습니다.
데이터베이스의 코드와 일부 구성 파일 정보는 생략되며 주로 JavaScript의 코드는 다음과 같습니다.
$ (document) .ready (function () {$ document.getElementByIdx_x_x_x_x_x_x_x_x_x_x_x_x_x_x_x ( "show"); show.innerhtml = ""; var province = document.getElementByIdx_x_x_x_x_x_x_x_x_x_x_x_x ( "province"). value; if (province! = 0) {if (wind ActiveXobject ( "microsoft.xmlhttp");} xmlhttp.onreadystatechange = function () {if (xmlhttp.readystate == 4 && xmlhttp.status == 200) {show.innerhtml = xmlhttp.rspestext;}}}}}}}}}}} EncodeUricomponent (str); xmlhttp.open ( "get", "getcity.do?provinceid="+sssssssssssssssssssssssssss) ;xmlhttp.send(null);}} inction myarea (str) {if (window.xmlhttprequest) {xmlhttp = new xmlhttprequest ();} else {xmlhttp = new ActiveXobject ( "microsoft.xmlhttp");} xmlhttp.onreadystatechange = function () {if (xmlhttp.readystate == 4 && xmlhttp.status == 200) {var show2 = document.getElementByIdx_x_x_x_x_x_x_x_x_x_x_x_x ( "show2"); show2.innerhtml = xmlhttp.responsetxt;}} var ss = EncodeUricomponent (str); xmlhttp.open ( "get", "getarea.do?cityid="+ssssssssssssssssssssssssssssssssssssssssssssss ,true); xmlhttp.send(null);} HTML 페이지의 코드는 다음과 같습니다.
위치
행동의 코드는 다음과 같습니다.
package mobi.zhangsheng.jiejia.action; import java.io.ioexception; import java.io.printwriter; import java.util.list; import javax.annotation.resource; import javax.servlet.http.httpervletrequest; httpresponse; org.apache.struts2.servletactioncontext; import org.springframework.stereotyp.controller; import mobi.zhangsheng.zhangsheng.zhangsheng.zhangsheng.zhangsheng.zhangsheng.zhangsheng.zhangsheng.zhangsheng.zhangsheng 지방은 {private int provinceid; private int cityId; @ResourcePrivate arearVice as; @ResourcePrivate AgentService ags; public int getProvinceId () {return provinceid;} public void setprovinceid (int provinceid) {this.provinceid = public getcityId (returncity in}} {reflice -setcityid; CityId) {this.cityId = cityId;} public void getProvince () {list provinceList = as.getAreAsPrvInceList (); httpservletResponse resp = servletactionContext.getResponse (); httpservletrequest request = servletactionContext.getRequest (); // resp.setContentType ( "XML"); resp.setContentType ( "text/html"); resp.SetchAracterEncoding ( "utf-8"); trinkriter out = resp.writer (); out.print ( ");"); ");"); (ioException e) {e.printstacktrace ();}} public void getCity () {list cityList = as.getAreascityList (provinceId); httpservletResponse resp = servletActionContext.getResponse (); // resp.setContentType ( "XML"); resp.setContentType ( "text/html"); resp.SetchAracterEncoding ( "utf-8"); trywriter out = resp.writer (); out.print ( ");"); ");"); (ioException e) {e.printstacktrace ();}} public void getArea () {list arealist = as.getAreascityList (cityId); if (arealist.size () == 0) {httpservletResponse resp = servletActionContext.getResponse (); resp.setContentType ( "text/html"); resp.SetchAracterEncoding ( "utf-8"); try {printwriter out = resp.getWriter (); out.print ( ");} catch (ioexception e) {e.printstacktrace ()}}}}}}}기본 기능 코드가 모두 있습니다. 이해하지 못하면 QQ : 1037139984로 문의하십시오. 모든 좋은 개발, 함께 배우고 함께 성장하기를 바랍니다.