这篇文章主要为大家详细介绍了Ajax实现二级联动菜单,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例为大家分享了Ajax二级联动菜单的具体代码,供大家参考,具体内容如下
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 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
<?xml version="1.0" encoding="UTF-8"?>