JavaScript Ajax Instance __ajax

Source: Internet
Author: User
Tags flush stringbuffer

The original ecology of simple JavaScript Ajax is only for the record:


Page code

<%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8"%> <% String Path = Request.getcontextpath () 
; 
String basepath = request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +path+ "/"; %> <! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >  

Background
public class Provinceaction extends Action {/* generated Methods//** * Method Execute * @param mapping * @param form * @param request * @param response * @return Actionforward/Public Actionforward Execute ( actionmapping mapping, Actionform form, httpservletrequest request, httpservletresponse response) {//Provinceform 
   
  Provinceform = (provinceform) Form; 
   
  System.out.println ("---------------Province is requested!------------------"); 
   
  String method = Request.getparameter (' method '); 
  String pr[] = {"Beijing", "Tianjin", "Shanghai", "Guangzhou", "Hebei", "Shandong"}; 
  String city[] = {"1", "2", "3", "4", "5", "6"}; 
  StringBuffer sb = new StringBuffer (); if (Method!=null&&method.trim (). Length () >0) {try {Response.setcontenttype () ("Text/xml;charset=utf -8 "); 
    This sentence and the following must not be reversed position, otherwise the page will appear garbled printwriter pw = Response.getwriter (); 
     
    Sb.append ("<?xml version=\" 1.0\ "encoding=\" utf-8\ "?>"); if (Method.equalsignorecase ("innitProvince ")) {sb.append (" <province> "); 
      for (Object obj:pr) {String pro = (string) obj; 
     Sb.append ("<name>" +pro+ "</name>"); 
     } sb.append ("</province>"); 
     Pw.write (Sb.tostring ()); 
    Pw.flush (); 
     else {sb.append ("<province>"); 
      for (Object obj:city) {String pro = (string) obj; 
     Sb.append ("<name>" +pro+ "</name>"); 
     } sb.append ("</province>"); 
     Pw.write (Sb.tostring ()); 
    Pw.flush (); 
   } catch (IOException e) {e.printstacktrace (); 
} return null;  } 
}




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.