论坛首页 入门技术论坛

ajax的二级级联

浏览 1183 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2008-12-22  

protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession();
        response.setContentType("text/xml; charset=GB2312");
        response.setHeader("Cache-Control","no-store");
        response.setHeader("Pragrma","no-cache");
        PrintWriter out = response.getWriter();
        String passWord ;
        if(request.getParameter("passWord") == null){
            passWord = " ";
        }else{
            passWord = new String(request.getParameter("passWord").getBytes("ISO8859_1"),"gb2312");
        }
        String userName = new String(request.getParameter("userName").getBytes("ISO8859_1"),"gb2312");
        if(passWord.equalsIgnoreCase("zzq")){
            UserBean user = new UserBean();
            user.setUserName(userName);
            session.setAttribute("user", user);
            out.print("true");
            out.close();
        }else{
            out.print("false");
            out.close();
        }
    }

CheckName也是Servlet
response.setContentType("text/xml; charset=GB2312");
        response.setHeader("Cache-Control","no-store");
        response.setHeader("Pragrma","no-cache");
        PrintWriter out = response.getWriter();
        String userName ;
        if(request.getParameter("userName") == null){
            userName = " ";
        }else{
            userName = new String(request.getParameter("userName").getBytes("ISO8859_1"),"gb2312");
        }
        if(userName.equalsIgnoreCase("zzq")){
            out.print("true");
            out.close();
        }else{
            out.print("false");
            out.close();
        }
DyListServlet
//直接生成xml文件
        response.setHeader("content-type", "text/xml;charset=GB2312");
        String dylist = new String(request.getParameter("adeName").getBytes("ISO8859_1"),"gb2312");
        StringBuffer sb = new StringBuffer();
        sb.append("<?xml version=\"1.0\" encoding=\"gb2312\"?>\n");
        sb.append("<response>");
        if(dylist.equalsIgnoreCase("湖北")){
            sb.append("<adname>武汉</adname>");
            sb.append("<adname>宜昌</adname>");
            sb.append("<adname>荆洲</adname>");
            sb.append("<adname>其它</adname>");
           
        }else if(dylist.equalsIgnoreCase("湖南")){
            sb.append("<adname>长沙</adname>");
            sb.append("<adname>岳阳</adname>");
            sb.append("<adname>其他</adname>");
        }else if(dylist.equalsIgnoreCase("陕西"))
        {
        sb.append("<adname>西安</adname>");
            sb.append("<adname>宝鸡</adname>");
            sb.append("<adname>渭南</adname>");
            sb.append("<adname>延安</adname>");
            sb.append("<adname>安康</adname>");
        }else{
            sb.append("<adname>香港</adname>");
            sb.append("<adname>澳门</adname>");
            sb.append("<adname>上海</adname>");
            sb.append("<adname>北京</adname>");
            sb.append("<adname>其他</adname>");
        }
        sb.append("</response>");
        PrintWriter out = response.getWriter();
        out.println(sb.toString());
        out.flush();
        out.close();
UserBean

private String userName ;
public String getUserName()
{
......
}
public void setUserName(String userName) {
       ........
    }

 

论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics