mysql省市区怎么 mysql地理位置( 三 )


package com.xiaojie.servlet;
import java.io.IOException;
import java.lang.reflect.Method;
import java.sql.SQLException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.xiaojie.beans.City;
import com.xiaojie.beans.County;
import com.xiaojie.beans.Province;
import com.xiaojie.dao.DAO;
/**
* Servlet implementation class ThreeactiondServlet
*/
@WebServlet("/threeactiondServlet")
public class ThreeactiondServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String methodname=request.getParameter("method");
try {
Method method=getClass().getDeclaredMethod(methodname,HttpServletRequest.class,HttpServletResponse.class);
method.invoke(this, request,response);//调用各自的方法
} catch (Exception e) {
e.printStackTrace();
}
}
private DAO dao=new DAO();
protected void province(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, ClassNotFoundException, SQLException {
System.out.println("province的servlet进入了");
String sql="select province_id,province_name from province";
ListProvince provinces=dao.getprovince(sql);
request.setAttribute("provinces", provinces);
System.out.println(provinces);
//注意:这里不能用重定向的形式 , 因为我们好不容易在request请求域中存储了省的信息,目的是在前台页面中能够从请求域中获取到我们存在数据库中的值
//故这里只能用转发的方式
request.getRequestDispatcher("/index2.jsp").forward(request, response);
}
protected void city(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, ClassNotFoundException, SQLException {
System.out.println("city的servlet进入了");
String province_id=request.getParameter("province_id");
String sql="select city_id,city_name from city where province_id=?";
ListCity cities=dao.getcity(sql,Integer.parseInt(province_id));
ObjectMapper mapper=new ObjectMapper();
String result=mapper.writeValueAsString(cities);
System.out.println(result);
response.setContentType("text/javascript");
response.getWriter().print(result);
}
protected void county(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, ClassNotFoundException, SQLException {
System.out.println("county的servlet进入了");
String city_id=request.getParameter("city_id");
String sql="select county_id,county_name from county where city_id=?";
ListCounty counties=dao.getcounty(sql,Integer.parseInt(city_id));
ObjectMapper mapper=new ObjectMapper();
String result=mapper.writeValueAsString(counties);
System.out.println(result);
response.setContentType("text/javascript");
response.getWriter().print(result);
}
}
关于mysql省市区怎么和mysql地理位置的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。

推荐阅读