jQuery+jsp下拉框联动获取本地数据的方法(附源码(2)

import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import net.sf.json.JSONArray; public class CarJsonServlet extends HttpServlet { 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.setHeader("Cache-Control", "no-cache"); response.setContentType("text/json;charset=UTF-8"); request.setCharacterEncoding("UTF-8"); //得到type,keyword的值 String type = request.getParameter("type"); String keyword = request.getParameter("keyword"); JSONArray jsonArrayResult = new JSONArray(); if ("top".equals(type)) { if ("BMW".equals(keyword)) { jsonArrayResult.add("316ti"); jsonArrayResult.add("6ercupe"); } else if ("Audi".equals(keyword)) { jsonArrayResult.add("tt"); } else if ("VW".equals(keyword)) { jsonArrayResult.add("Golf4"); } } else if ("sub".equals(type)) { if ("tt".equals(keyword)) { jsonArrayResult.add("rha"); jsonArrayResult.add("rhb"); jsonArrayResult.add("rhc"); } else if ("316ti".equals(keyword)) { jsonArrayResult.add("rha"); jsonArrayResult.add("rhb"); } else if ("6ercupe".equals(keyword)) { jsonArrayResult.add("rha"); jsonArrayResult.add("rhb"); jsonArrayResult.add("rhc"); } else if ("Golf4".equals(keyword)) { jsonArrayResult.add("rha"); jsonArrayResult.add("rhb"); } } PrintWriter out = response.getWriter(); out.write(jsonArrayResult.toString()); out.flush(); out.close(); } }

配置文件web.xml

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wgzzgd.html