Java provinces and cities cascading drop-down Menu Instance Code _java

Source: Internet
Author: User

This example for you to share the Java provinces and cities of the specific code for your reference, the specific content as follows

1.loadareaservlet.java

Package com.scce.servlet;
Import java.io.IOException;
Import Java.io.PrintWriter;
 
Import java.util.ArrayList;
Import javax.servlet.ServletException;
Import Javax.servlet.http.HttpServlet;
Import Javax.servlet.http.HttpServletRequest;
 
Import Javax.servlet.http.HttpServletResponse;
 
Import Net.sf.json.JSONArray;
Import com.scce.pojo.City;
 
Import Com.scce.pojo.Prov;
 
  public class Loadareaservlet extends HttpServlet {private static final long serialversionuid = 1L;
      public void doget (HttpServletRequest request, httpservletresponse response) throws Servletexception, IOException {
  This.dopost (request, response); public void DoPost (HttpServletRequest request, httpservletresponse response) throws Servletexception, Ioex
    ception {response.setcontenttype ("text/html;charset=utf-8");
    Request.setcharacterencoding ("Utf-8");
    PrintWriter out = Response.getwriter ();
    arraylist<prov> Provs = new arraylist<prov> (); StrinG Provinceid = Request.getparameter ("Provinceid");
    if (provinceid== "" | | | provinceid==null) {System.out.println ("Loading prefecture-level information");
    Prov Pro1 = new Prov ();
    Pro1.setid (0);
    Pro1.setprovincename ("Hubei");
    Prov Pro2 = new Prov ();
    Pro2.setid (1);
    Pro2.setprovincename ("Hunan");
    Prov Pro3 = new Prov ();
    Pro3.setid (2);
    Pro3.setprovincename ("Guangdong");
    Prov Pro4 = new Prov ();
    Pro4.setid (3);
    Pro4.setprovincename ("Guangxi");
    Provs.add (Pro1);
    Provs.add (PRO2);
    Provs.add (PRO3);
    Provs.add (Pro4); System.out.println (Jsonarray.fromobject (Provs). toString ());
    [{"id": 0, "provincename": "Hubei"},{}] Out.print (Jsonarray.fromobject (Provs). toString ());
      }else{arraylist<city> citys = new arraylist<city> ();
        if (Provinceid.equals ("0")) {City city1 = new City ();
        City1.setid (0);
        City1.setcityname ("Wuhan City");
        City City2 = new City ();
        City2.setid (1);
        City2.setcityname ("Huangshi"); City City3 = new City ();
        City3.setid (2);
        City3.setcityname ("Shiyan");
        Citys.add (city1);
        Citys.add (City2);
      Citys.add (CITY3);
        } if (Provinceid.equals ("1")) {City city1 = new City ();
        City1.setid (0);
        City1.setcityname ("Changsha");
        City City2 = new City ();
        City2.setid (1);
        City2.setcityname ("Yueyang");
        City City3 = new City ();
        City3.setid (2);
        City3.setcityname ("Xiangtan");
        Citys.add (city1);
        Citys.add (City2);
      Citys.add (CITY3);
      } System.out.println (Jsonarray.fromobject (citys). toString ());
    Out.print (Jsonarray.fromobject (citys). toString ()); }  
  }
   
 
}

2.test1.html

<! DOCTYPE html>  

The above is the entire content of this article, I hope to learn Java program to help you.

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.