Ajax implementation of the two-level linkage menu __ajax

Source: Internet
Author: User

index.jsp

<%@ page language= "java" pageencoding= "UTF-8"%>  

Selectservlet.java

Package com;

Import java.io.IOException;
Import javax.servlet.ServletException;
Import Javax.servlet.http.HttpServlet;
Import Javax.servlet.http.HttpServletRequest;
Import Javax.servlet.http.HttpServletResponse; /*** * * * @author ZDW * */public class Selectservlet extends HttpServlet {private static final long Serialversi

    Onuid = 1L;
    Public Selectservlet () {super ();
    public void Destroy () {Super.destroy (); public void doget (HttpServletRequest request, httpservletresponse response) throws Servletexception, IO
        Exception {//Response.setcharacterencoding ("GBK");
        Response.setcontenttype ("Text/xml");
        Response.setheader ("Cache-control", "No-cache");
        Request.setcharacterencoding ("GBK");
        Response.setcharacterencoding ("UTF-8");
        String Targetid = request.getparameter ("id"). toString ();
        System.out.println (Targetid); Gets the value of the parameter ID in the request String Xml_start= "<selects>";
        String xml_end = "</selects>";

        String xml = ""; if (Targetid.equalsignorecase ("0")) {XML = <select><value>0</value><text> Please select
        </text></select> "; else if (Targetid.equalsignorecase ("1")) {xml = "<select><value>1</value><text
            > Changping </text></select> ";
            XML = "<select><value>2</value><text> Fengtai </text></select>";
            XML + = "<select><value>3</value><text> Haidian </text></select>";
        XML = "<select><value>4</value><text> Chaoyang </text></select>"; else if (Targetid.equalsignorecase ("2")) {xml = "<select><value>1</value><text
            > Tanggu District </text></select> "; XML = "<select><value>2</value><text> Hangu District </text>&Lt;/select> ";
            XML + = "<select><value>3</value><text> Grand Port District </text></select>";
        XML + = "<select><value>4</value><text> Dongli District </text></select>"; else {//If 3, returns the following character XML = "<select><value>1</value><text> Jinan </text>&
            Lt;/select> ";
            XML = "<select><value>2</value><text> qingdao </text></select>";
            XML = "<select><value>3</value><text> Zibo </text></select>";
        XML = "<select><value>4</value><text> Zaozhuang </text></select>";
        String Last_xml = xml_start + xml + xml_end;

    Response.getwriter (). write (Last_xml); public void DoPost (HttpServletRequest request, httpservletresponse response) throws Servletexception, I
    oexception {doget (request, response);

    }public void Init () throws servletexception {}}
 

Xml

<?xml version= "1.0" encoding= "UTF-8"?> <web-app version= "
2.4" xmlns= "HTTP://JAVA.SUN.COM/XML/NS/J2EE"
    xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemalocation= "http://java.sun.com/xml/ns/ Java 
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd ">
    <servlet>
        <servlet-name> Selectservlet</servlet-name>
        <servlet-class>com. selectservlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name> selectservlet</servlet-name>
        <url-pattern>/select</url-pattern>
    </ servlet-mapping>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
</web-app>


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.