java성 시급 연결 메뉴 실례 코드
1.LoadAreaServlet.java
package com.scce.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.json.JSONArray;
import com.scce.pojo.City;
import com.scce.pojo.Prov;
public class LoadAreaServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
request.setCharacterEncoding("utf-8");
PrintWriter out = response.getWriter();
ArrayList<Prov> provs = new ArrayList<Prov>();
String provinceID = request.getParameter("provinceID");
if (provinceID=="" || provinceID==null) {
System.out.println(" ");
Prov pro1 = new Prov();
pro1.setId(0);
pro1.setProvinceName(" ");
Prov pro2 = new Prov();
pro2.setId(1);
pro2.setProvinceName(" ");
Prov pro3 = new Prov();
pro3.setId(2);
pro3.setProvinceName(" ");
Prov pro4 = new Prov();
pro4.setId(3);
pro4.setProvinceName(" ");
provs.add(pro1);
provs.add(pro2);
provs.add(pro3);
provs.add(pro4);
System.out.println(JSONArray.fromObject(provs).toString()); //[{"id":0,"provinceName":" "},{}]
out.print(JSONArray.fromObject(provs).toString());
}else{
ArrayList<City> citys = new ArrayList<City>();
if (provinceID.equals("0")) {
City city1 = new City();
city1.setId(0);
city1.setCityName(" ");
City city2 = new City();
city2.setId(1);
city2.setCityName(" ");
City city3 = new City();
city3.setId(2);
city3.setCityName(" ");
citys.add(city1);
citys.add(city2);
citys.add(city3);
}
if (provinceID.equals("1")) {
City city1 = new City();
city1.setId(0);
city1.setCityName(" ");
City city2 = new City();
city2.setId(1);
city2.setCityName(" ");
City city3 = new City();
city3.setId(2);
city3.setCityName(" ");
citys.add(city1);
citys.add(city2);
citys.add(city3);
}
System.out.println(JSONArray.fromObject(citys).toString());
out.print(JSONArray.fromObject(citys).toString());
}
}
}
2.test1.html
<!DOCTYPE html>
<html>
<head>
<title>chapter4-test1</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../UI/themes/icon.css" type="text/css"></link>
<link rel="stylesheet" href="../UI/themes/default/easyui.css" type="text/css"></link>
<!-- <script type="text/javascript" src="../js/jquery-1.8.2.min.js"></script> -->
<script type="text/javascript" src="../UI/jquery.min.js"></script>
<script type="text/javascript" src="../UI/jquery.easyui.min.js"></script>
<script type="text/javascript" src="../UI/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript">
//LoadAreaServlet
/* var dataCombobox=[{"id":1,"provinceName":" "},
{"id":2,"provinceName":" ","selected":true},
{"id":3,"provinceName":" "},
{"id":4,"provinceName":" "}
]; */
$(function () {
$("#province").combobox({
width: 150,
valueField: 'id', //1
textField: 'provinceName', //
editable: false,
// data:dataCombobox //
url:'../LoadAreaServlet',
method:'post',
onLoadSuccess:function(data){
var provId = $("#province").combobox("getValue");
loadCity(provId);
},
onSelect:function(recode){
loadCity(recode.id);
}
});
});
function loadCity(provId){
$("#city").combobox({
width: 150,
valueField: 'id', //1
textField: 'cityName', //
editable: false,
// data:dataCombobox //
url:'../LoadAreaServlet?provinceID='+provId,
method:'post'
});
}
</script>
</head>
<body>
:
<select id="province" >
<option value="0"> ..</option>
</select>
<br/>
:
<select id="city" >
<option value=""> ..</option>
</select>
</body>
</html>
이상은 본고의 전체 내용입니다. 여러분이java프로그래밍을 배우는 데 도움이 되기를 바랍니다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
38. Java의 Leetcode 솔루션텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.