原文地址:http://xiongjiajia.iteye.com/blog/1319245
1.简单的级联下拉框
- <?xmlversion="1.0"encoding="UTF-8"?>
- <web-appxmlns="http://java.sun.com/xml/ns/javaee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"version="2.5"xsi:schemaLocation="http://java.sun.com/xml/ns/javaeehttp://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
- servletservlet-name>SelectCityServlet</servlet-class>com.demo.servlet.SelectCityServletservlet-mappingurl-pattern>/servlet/SelectCityServletwelcome-file-listwelcome-file>index.jspweb-app>
- packagecom.demo.servlet;
- importjava.io.IOException;
- importjava.io.PrintWriter;
- importjavax.servlet.ServletException;
- importjavax.servlet.http.HttpServlet;
- importjavax.servlet.http.HttpServletRequest;
- importjavax.servlet.http.HttpServletResponse;
- publicclassSelectCityServletextendsHttpServlet{
- publicSelectCityServlet(){super();}
- voiddestory(){super.destroy();}
- @Override
- protectedvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)
- throwsServletException,IOException{
- //TODOAuto-generatedmethodstub
- response.setContentType("text/xml");
- response.setHeader("Cache-Control","no-cache");
- response.setCharacterEncoding("UTF-8");
- Stringstate=request.getParameter("state");
- StringBufferbuffer=newStringBuffer("<state>");
- if("hn".equals(state)){
- buffer.append("<city>郑州</city><city>洛阳</city>");
- }elseif("hb".equals(state)){
- buffer.append("<city>武汉</city><city>荆州</city><city>黄冈</city>");
- }
- buffer.append("</state>");
- PrintWriterout=response.getWriter();
- out.write(buffer.toString());
- out.close();
- }