ajax jsp中二级下拉框联动 固定数据

在index.jsp中的代码如下。

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>

   
        二级菜单联动演示
       
   

   
       


           

               
                   
                       
                   
                   
                       
                   
                   
                       
                   
               

                            二级联动示例
                       

                           
                           
                       

                       

           

       

   

 

在后台SelectServlet的代码如下

package com.pcic.nong.jdbc;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class SelectServlet extends HttpServlet
{

private static final long serialVersionUID = 1L;

public SelectServlet()
{
super();
}

public void destroy()
{
super.destroy();
}

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
// 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);
// 获得请求中参数为id的值
String xml_start = "";
String xml_end = "
";
String xml = "";

if (targetId.equalsIgnoreCase("0"))
{
xml = "";
} else if (targetId.equalsIgnoreCase("1"))
{
xml = "";
xml += "";
xml += "";
xml += "";
} else if (targetId.equalsIgnoreCase("2"))
{
xml = "";
xml += "";
xml += "";
xml += "";
} else
{// 如果是3,则返回下面的字符
xml = "";
xml += "";
xml += "";
xml += "";
}

String last_xml = xml_start + xml + xml_end;
response.getWriter().write(last_xml);

}

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
doGet(request, response);
}

public void init() throws ServletException
{
}

}

 


在web.xml里面这样配置

 


 xmlns="http://java.sun.com/xml/ns/javaee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
 http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

 
  SelectServlet
  com.pcic.nong.jdbc.SelectServlet
 

 
  SelectServlet
  /select
 


index.jsp

 

你可能感兴趣的:(转摘学习Ajax)