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地理位置的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。
推荐阅读
- 行业市场如何营销,市场营销企业应该怎么做
- wordpress在线阅读主题,wordpress文章主题
- 爱丽丝游戏益智,爱丽丝动作游戏
- 直播活动引流话术技巧,直播宣传与引流的六种方法是什么?
- js三元运算符判断5个条件,js 三元判断
- ppt怎么加到附件,ppt内怎么加入附件
- 斗鱼直播钓钓,斗鱼直播钓钓鱼视频
- php数据库字段映射 php怎么将数据库中的数据显示出来
- 怎么导入鸿蒙主题桌面,鸿蒙如何导入主题