package com.servlet;  

      

    import java.io.IOException;  

    import java.io.PrintWriter;  

      

    import javax.servlet.ServletException;  

    import javax.servlet.http.HttpServlet;  

    import javax.servlet.http.HttpServletRequest;  

    import javax.servlet.http.HttpServletResponse;  

      

    /**

     * Servlet implementation class CheckUser

     */  

    public class CheckUser extends HttpServlet {  

        private static final long serialVersionUID = 1L;  

             

       

        public CheckUser() {  

            super();  

            // TODO Auto-generated constructor stub  

        }  

      

        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {  

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

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

            username = new String(username.getBytes("iso8859-1"),"utf-8");  

            boolean ok = false;  

            if(username.length() < 6){  

                ok = false;  

            }else{  

                ok = true;  

            }  

            PrintWriter out = response.getWriter();  

            if(ok){  

                out.print(username+"合法");  

            }else{  

                out.print(username+"不合法");  

            }  

            out.flush();  

            out.close();  

        }  

      

        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {  

            // TODO Auto-generated method stub  

        }  

      

    }  

[xhtml] view plaincopy

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">  

    <html>  

    <head>  

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  

    <title>用户登录(处理中文乱码)</title>  

    <mce:script type="text/javascript"><!--  

        function check(v){  

            var xmlHttp;  

            if(window.XMLHttpRequest){  

                xmlHttp = new XMLHttpRequest();  

                if(xmlHttp.overrideMimeType){  

                    xmlHttp.overrideMimeType("text/html");  

                }  

            }else if(window.ActiveXObject){  

                var name = ["MSXML2.XMLHTTP","Mirosoft.XMLHTTP"];  

                for(var i = 0;i<activeNames.length;i++){  

                    try{  

                        xmlHttpRequest = new ActiveXObject(activeNames[i]);  

                        break;  

                        }catch(e){  

                            }  

                }  

            }  

            xmlHttp.open("GET","CheckUser?username="+encodeURI(document.getElementById("username").value),true);  

            //发送请求  

            xmlHttp.send(null);  

            xmlHttp.onreadystatechange = function(){  

                if(xmlHttp.readyState == 4){  

                    if(xmlHttp.status == 200){  

                        document.getElementById("uinfo").innerHTML = xmlHttp.responseText;  

                    }  

                }  

            };  

        }  

    // --></mce:script>  

    </head>  

    <body>  

    <form action="">  

    <table>  

        <tr>  

            <td>userName:</td>  

            <td><input width='200' id='username' onblur="check(this);"><span id='uinfo'></span></td>  

        </tr>  

        <tr>  

            <td>password:</td>  

            <td><input width='200' type="password"></td>  

        </tr>  

        <tr>  

            <td><input type='button' value="login"></td>  

            <td><input type='button' value="submit"></td>  

        </tr>  

    </table>  

    </form>  

    </body>  

    </html>

处理get中文乱码的更多相关文章

  1. java中文乱码解决之道(一)-----认识字符集

    沉寂了许久(大概有三个多月了吧),LZ"按捺不住"开始写博了! java编码中的中文问题是一个老生常谈的问题了,每次遇到中文乱码LZ要么是按照以前的经验修改,要么则是baidu.c ...

  2. MAC下 mysql不能插入中文和中文乱码的问题总结

    MAC下 mysql不能插入中文和中文乱码的问题总结 前言 本文中所提到的问题解决方案,都是基于mac环境下的,但其他环境,比如windows应该也适用. 问题描述 本文解决下边两个问题: 往mysq ...

  3. java中文乱码解决之道(九)-----总结

    乱码,我们前台展示的杀手,可能有些朋友和我的经历一样:遇到乱码先按照自己的经验来解决,如果没有解决就google,运气好一搜就可以解决,运气不好可能够你折腾一番了.LZ之所以写这个系列博客就是因为遇到 ...

  4. 解决springmvc+mybatis+mysql中文乱码问题【转】

    这篇文章主要介绍了解决java中springmvc+mybatis+mysql中文乱码问题的相关资料,需要的朋友可以参考下 近日使用ajax请求springmvc后台查询mysql数据库,页面显示中文 ...

  5. freemarker页面中文乱码

    一.前言 简单的记录freemarker遇到的错误问题:ftl页面中文乱码 由于freemarker整合在ssm框架中,所以笔者直接贴配置代码 <beans xmlns="http:/ ...

  6. tomcat项目中文乱码问题解决方法

    在部署tomcat项目时经常会遇到中文乱码问题,解决的方法可参考以下步骤. 1.更改Tomcat安装目录下的conf\server.xml,指定浏览器的编码格式为"utf-8"格式 ...

  7. IE下get传中文乱码的问题 -- 解决方案 (js)

    W3school 函数 JavaScript 全局对象 定义和用法 encodeURI() 函数可把字符串作为 URI 进行编码. 语法 encodeURI(URIstring) 参数 描述 URIs ...

  8. JSP和Servlet的中文乱码处理

    JSP和Servlet的中文乱码处理 前几天学习了JSP和Servlet中有关中文乱码的一些问题,写成了博客,今天进行更新一下.应该是可以解决日常的乱码问题了.现在作以下总结希望对需要的人有所帮助.我 ...

  9. Git bash下中文乱码问题

    Git bash下中文乱码--解决方案 解决办法1: 在git bash下,右键 出现下图,选择options: 选择"Text" 将Character set设置为 UTF-8 ...

  10. mysql表单输入数据出现中文乱码解决方法

    MySQL会出现中文乱码的原因在于1.server本身设定问题,一般来说是latin1 2.建库建表时没有制定编码格式. 解决方法: 1.建库的时候 CREATE DATABASE test CHAR ...

随机推荐

  1. Building an FTP Test Plan

    参考:http://jmeter.apache.org/usermanual/build-ftp-test-plan.html 1.创建一个线程组 2.线程组--->添加--->配置元件- ...

  2. Linux 进程管理 进程优先级管理

    Linux进程优先级 Linux 是一个多用户.多任务的操作系统,系统中通常运行着非常多的进程.但是 CPU 在一个时钟周期内只能运算一条指令(现在的 CPU 采用了多线程.多核心技术,所以在一个时钟 ...

  3. this()必须放在构造方法的第一条

    public class A { String name; int age; public A() { this("Jack",23); } public A(String nam ...

  4. ES6中Json、String、Map、Object之间的转换

    /** *字符串转json * */ static stringToJson(data){ return JSON.parse(data); } /** *json转字符串 */ static jso ...

  5. (补充一)CountDownLatch

    引言:  在学习单例模式时候,用到了锁synchronized的概念,在多线程中又用到了CountDownLatch的概念 CountDownLatch是一个同步工具类,它允许一个或多个线程一直等待, ...

  6. Spring Cloud2.0之Oauth2环境搭建(授权码模式和密码授权模式)

    oauth2 server 微服务授权中心,    github源码  https://github.com/spring-cloud/spring-cloud-security 对微服务接口做一些权 ...

  7. 关于Block汇总

    //使用总结: //1.当block里面会有b类相关的参数要回调回去的时候,属性用copy修饰,将其拷贝到堆里面,这样即便栈释放掉了,b类的指针也在堆中存在,能够成功的回调回去. //Block默认存 ...

  8. 基于主从复制的Mysql双机热备+amoeba实现读写分离、均衡负载

    读写分离指的是客户只能在主服务器上写,只能在从服务器上读,当然了,这也是要看配置,你可以在主服务器配置读的功能,但是在从服务器上只能读不能写,因为从服务器是基于binlog对主服务器的复制,如果在从服 ...

  9. JavaScript常用知识点整理——思维导图

    如图 思维导图图片链接 http://www.edrawsoft.cn/viewer/public/s/b8327462051289 有道云笔记图片链接 http://note.youdao.com/ ...

  10. JNI_Z_05_方法的操作(没有String类型的参数)

    1.步骤: (1).获取 jclass (2).获取 method的id (3).调用 method ZC: 貌似 JNI里面 操作 类的方法,完全是 无视 访问权限的... 然而 static的方法 ...