JSONLIB 转换JSON数据:
- JSONArray :将数组或List集合转成JSON.
- JSONObject :将对象或Map集合转成JSON.
新增三个包:
1.查询省份
JsonProvinceServlet:
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
response.setContentType("text/html;charset=UTF-8");
request.setCharacterEncoding("UTF-8");
JqProvinceCityService jqProvinceCityService = new JqProvinceCityService();
List<Province> list = jqProvinceCityService.findProvince();
request.setAttribute("list", list);
request.getRequestDispatcher("/Json_province_city/JSON_province_city.jsp").forward(request, response);
} catch (SQLException e) {
e.printStackTrace();
}
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request,response);
}
2.查询城市
JsonCityServlet:
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding(