初学ajax,实现用户名重复提示、二级/三级联动下拉框

初学ajax,实现异步操作!

源代码下载链接:http://download.csdn.net/detail/yan13507001470/9911744

初学ajax,实现用户名重复提示、二级/三级联动下拉框_第1张图片初学ajax,实现用户名重复提示、二级/三级联动下拉框_第2张图片               初学ajax,实现用户名重复提示、二级/三级联动下拉框_第3张图片初学ajax,实现用户名重复提示、二级/三级联动下拉框_第4张图片


以下为三级联动下拉框部分代码


jsp页面部分代码

下拉框:               

servlet代码

@WebServlet("/ProvinceCityCountyServlet")
public class ProvinceCityCountyServlet extends HttpServlet {
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		String method = request.getParameter("method");
		
		if(method.equals("ajaxone")){
			
			response.setContentType("text/xml;charset=utf-8");
			String provinceId = request.getParameter("provinceId");
			
			CityService cityService = new CityService();
			List allCities = cityService.findByFKId(Integer.parseInt(provinceId));
			
			PrintWriter pw = response.getWriter();
			pw.write("");
			pw.write("");
			
			for(int i=0;i"+city.getName()+"");
			}
			
			pw.write("");
			pw.flush();
			pw.close();
			
		}else if (method.equals("ajaxtwo")) {
			response.setContentType("text/xml;charset=utf-8");
			String cityId = request.getParameter("cityId");
			
			CountyService countyService = new CountyService();
			List allCounties = countyService.findByFKId(Integer.parseInt(cityId));
			
			PrintWriter pw = response.getWriter();
			pw.write("");
			pw.write("");
			
			for(int i=0;i"+county.getName()+"");
			}
			
			pw.write("");
			pw.flush();
			pw.close();
			
		}else if (method.equals("fromSubmit")) {	//提交获取数据
			
			String countId = request.getParameter("countyId");
			
			CountyService countyService = new CountyService();
			County county = countyService.findById(Integer.parseInt(countId));
			System.out.println("县:"+county.getName());
			
			CityService cityService = new CityService();
			City city = cityService.findById(county.getCity_id());
			System.out.println("城市:"+city.getName());
			
			ProvinceServince provinceServince = new ProvinceServince();
			Province province = provinceServince.findById(city.getProvince_id());
			System.out.println("省:"+province.getName());
			
			System.out.println(province.getName()+"-"+city.getName()+"-"+county.getName());
			
		}else {
			ProvinceServince provinceServince = new ProvinceServince();
			List allProvinces = provinceServince.findAll();
			
			request.setAttribute("allProvinces", allProvinces);
			request.getRequestDispatcher("/Province_city_county.jsp").forward(request, response);
			
		}
		
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}
}

注:有什么写的不对的地方,请提出来,感谢


你可能感兴趣的:(java)