j2ee之AJAX二级联动效果

网友投稿 233 2023-04-16


j2ee之AJAX二级联动效果

本文实例为大家分享了AJAX二级联动效果的具体代码,供大家参考,具体内容如下

Ajax.js

var createAjax = function(){

var ajax = null;

try{

ajax = new ActiveXObject("microsoft.xmlhttp");

}catch(e1){

try{

ajax = new XMLHttpRequest();

}catch(e2){

alert("请换掉你的浏览器");

}

}

return ajax;

}

test3.xml

<%@ page language="java" contentType="text/html; charset=UTF-8"

pageEncoding="UTF-8"%>

<%

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

SelectServlet.java

package com.newtouch.servlet;

import java.io.IOException;

import javax.servlet.ServletException;

import javax.servlet.annotation.WebServlet;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

/**

* Servlet implementation class SelectServlet

*/

@WebServlet("/SelectServlet")

public class SelectServlet extends HttpServlet {

private static final long serialVersionUID = 1L;

/**

* @see HttpServlet#HttpServlet()

*/

public SelectServlet() {

super();

// TODO Auto-generated constructor stub

}

/**

* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse

* response)

*/

protected void doGet(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

// TODO Auto-generated method stub

response.getWriter().append("Served at: ").append(request.getContextPath());

}

/**

* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse

* response)

*/

protected void doPost(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

request.setCharacterEncoding("utf-8");

// 这里是text/xml是把数据放到了xml中

response.setContentType("text/xml;charset=utf-8");

String province = request.getParameter("province");

response.getWriter().write("");

response.getWriter().write("");

if ("江苏".equals(province)) {

response.getWriter().write("1");

response.getWriter().write("2");

response.getWriter().write("3");

response.getWriter().write("4");

} else if ("江西".equals(province)) {

response.getWriter().write("<cityOption>一");

response.getWriter().write("");

response.getWriter().write("");

response.getWriter().write("");

}

response.getWriter().write("");

}

}


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:spring自定义注解实现拦截器的实现方法
下一篇:java实现随机森林RandomForest的示例代码
相关文章

 发表评论

暂时没有评论,来抢沙发吧~