JSP页面显示乱码问题的解决方法-成都创新互联网站建设

关于创新互联

多方位宣传企业产品与服务 突出企业形象

公司简介 公司的服务 荣誉资质 新闻动态 联系我们

JSP页面显示乱码问题的解决方法

这篇文章主要介绍“JSP页面显示乱码问题的解决方法”,在日常操作中,相信很多人在JSP页面显示乱码问题的解决方法问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”JSP页面显示乱码问题的解决方法”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

我们提供的服务有:成都做网站、网站建设、微信公众号开发、网站优化、网站认证、二连浩特ssl等。为上千多家企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的二连浩特网站制作公司

一、JSP页面显示乱码

二、表单提交中文时出现乱码

三、数据库连接

大家在JSP的开发过程中,经常出现中文乱码的问题,可能一至困扰着您,我现在把我在JSP开发中遇到

的中文乱码的问题及解决办法写出来供大家参考。

一、JSP页面显示乱码
下面的显示页面(display.jsp)就出现乱码:

  JSP的中文处理title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> head> <body> <%  out.print("JSP的中文处理");  %> body> html></pre><p>对不同的WEB<a title="服务器" target="_blank" href="http://www.cdfuwuqi.com/">服务器</a>和不同的JDK版本,处理结果就不一样。原因:服务器使用的编码方式不同和浏览器对不同的字符显示结果不同而导致的。解决办法:在JSP页面中指定编码方式(gb2312),即在页面的***行加上:<%@ page="" contenttype="text/html; charset=gb2312">,就可以消除乱码了。完整页面如下<!--%@--></p><pre><%@ page contentType="text/html; charset=gb2312"%> <html> <head> <title>JSP的中文处理title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> head> <body> <%  out.print("JSP的中文处理");  %> body> html></pre><p>二、表单提交中文时出现乱码<br/>下面是一个提交页面(submit.jsp),代码如下:</p><pre><html> <head> <title>JSP的中文处理title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> head> <body> <form name="form1" method="post" action="process.jsp"> <div align="center"> <input type="text" name="name"> <input type="submit" name="Submit" value="Submit"> div> form> body> html></pre><p>下面是处理页面(process.jsp)代码:</p><pre><%@ page contentType="text/html; charset=gb2312"%> <html> <head> <title>JSP的中文处理title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> head>  <body> <%=request.getParameter("name")%> body> html></pre><p>如果submit.jsp提交英文字符能正确显示,如果提交中文时就会出现乱码。原因:浏览器默认使用UTF-8编码方式来发送请求,而UTF- 8和GB2312编码方式表示字符时不一样,这样就出现了不能识别字符。解决办法:通过request.seCharacterEncoding ("gb2312")对请求进行统一编码,就实现了中文的正常显示。修改后的process.jsp代码如下:</p><pre><%@ page contentType="text/html; charset=gb2312"%> <%  request.seCharacterEncoding("gb2312");  %> <html> <head> <title>JSP的中文处理title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> head>  <body> <%=request.getParameter("name")%> body> html></pre><p>三、数据库连接出现乱码<br/>只要涉及中文的地方全部是乱码,解决办法:在数据库的数据库URL中加上<br/>useUnicode=true&characterEncoding=GBK 就OK了。</p><p>四、数据库的显示乱码<br/>在MySQL4.1.0中,varchar类型,text类型就会出现中文乱码,对于varchar类型把它设为binary属性就可以解决JSP页面显示乱码问题了</p><p>到此,关于“JSP页面显示乱码问题的解决方法”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注创新互联网站,小编会继续努力为大家带来更多实用的文章!</p>            
            
                        <br>
            分享文章:JSP页面显示乱码问题的解决方法            <br>
            URL标题:<a href="http://kswsj.cn/article/psidcp.html">http://kswsj.cn/article/psidcp.html</a>
        </div>
    </div>
    <div class="other">
        <h3>其他资讯</h3>
        <ul>
            <li>
                    <a href="/article/depisps.html">c语言随机函数取负数 c语言里随机函数</a>
                </li><li>
                    <a href="/article/depieih.html">k2路由器刷机 k2路由器刷机失败</a>
                </li><li>
                    <a href="/article/depiegj.html">叫路由器的狗 谁的狗叫路由器</a>
                </li><li>
                    <a href="/article/depiesj.html">c语言函数名命名规范 c语言函数的命名规范</a>
                </li><li>
                    <a href="/article/depieig.html">c语言2次方函数怎么写 c语言求2的n次方值</a>
                </li>        </ul>
    </div>
</div>
<div class="line"></div>
<!--底部-->
<footer id="5">
    <div class="foot1 container">
        <div class="list">
            <div class="item">
                <a href="javascript:;">
                    <span class="ico1"><i class="iconfont"></i><img src="/Public/Home/img/ewm.png" alt=""></span>
                    <strong>关注我们</strong>
                </a>
            </div>
            <div class="item">
                <a href="" target="_blank">
                    <span><i class="iconfont"></i></span>
                    <strong>索要报价</strong>
                </a>
            </div>
            <div class="item">
                <a href="" target="_blank">
                    <span><i class="iconfont"></i></span>
                    <strong>我要咨询</strong>
                </a>
            </div>
            <div class="item">
                <a href="" target="_blank">
                    <span><i class="iconfont"></i></span>
                    <strong>找到我们</strong>
                </a>
            </div>
            <div class="item">
                <a href="" target="_blank">
                    <span><i class="iconfont"></i></span>
                    <strong>投诉建议</strong>
                </a>
            </div>
        </div>
        <div class="tel">
            <dl>
                <tel><a href="tel:400-028-6601" target="_blank">400-028-6601</a></tel><br>
                <span>也许您需要专业的服务,欢迎来电咨询</span>
            </dl>
            <dl>
                <tel><a href="tel:18980820575" target="_blank">18980820575</a></tel><br>
                <span>您的需求,是我们前进的动力</span>
            </dl>
        </div>
    </div>
    <div class="friend">
        <div class="container">
            <span class="tit">友情链接:</span>
            <div class="inner">
                <a href="https://www.cdcxhl.com/sosuo.html" target="_blank">搜索引擎优化</a><a href="https://www.cdcxhl.com/app.html" target="_blank">成都app开发</a><a href="https://www.cdcxhl.com/xiyun.html" target="_blank">西云服务器托管</a><a href="https://www.cdcxhl.com/link/" target="_blank">买友情链接</a><a href="https://www.cdcxhl.com/security/" target="_blank">成都等保测评</a><a href="https://www.cdcxhl.com/google.html" target="_blank">成都谷歌推广</a><a href="https://www.cdcxhl.com/shoulu/" target="_blank">分类目录网站</a><a href="https://www.cdcxhl.com/ruanwen/" target="_blank">软文推广营销</a><a href="https://www.cdcxhl.com/tuoguan/yaan/" target="_blank">川西大数据中心</a><a href="https://www.cdxwcx.com/jifang/xiyun.html" target="_blank">西云移动机房</a><a href="https://www.cdcxhl.com/jigui/" target="_blank">机柜租用</a><a href="https://www.cdcxhl.com/sosuo.html" target="_blank">网站搜索引擎优化</a><a href="https://www.cdcxhl.com/mobile.html" target="_blank">成都手机网站制作公司</a><a href="https://www.cdcxhl.com/google.html" target="_blank">谷歌优化排名</a><a href="https://www.cdcxhl.com/xiangyingshi.html" target="_blank">成都响应式网站建设公司</a><a href="https://www.cdcxhl.com/cloud/" target="_blank">成都云服务器</a><a href="https://www.cdcxhl.com/tuoguan/yaan/" target="_blank">雅安服务器托管</a><a href="https://www.cdcxhl.com/waimao.html" target="_blank">成都外贸网站建设</a>            </div>
        </div>
    </div>
    <div class="foot">
        <div class="container">
            <div class="footNav">
                <h3>网站建设</h3>
                <a href="https://www.cdcxhl.com/" target="_blank">网站建设公司</a><a href="http://chengdu.cdcxhl.cn/H5/" target="_blank">成都响应式网站建设公司</a><a href="http://m.cdcxhl.cn/dingzhi/" target="_blank">高端定制网站建设</a>            </div>
            <div class="footNav">
                <h3>服务器托管</h3>
                <a href="https://www.cdcxhl.com/idc/zongshu.html" target="_blank">棕树服务器托管</a><a href="https://www.cdcxhl.com/jigui/" target="_blank">服务器机柜租用</a><a href="https://www.cdcxhl.com/jigui/" target="_blank">机柜租用</a>            </div>
            <div class="footNav">
                <h3>网站制作</h3>
                <a href="http://chengdu.cdcxhl.cn/qiye/" target="_blank">企业网站制作</a><a href="http://www.cxhljz.cn/" target="_blank">成都网站制作</a><a href="http://www.cqcxhl.com/" target="_blank">重庆网站制作</a>            </div>
            <div class="footNav">
                <h3>企业服务</h3>
                <a href="https://www.cdcxhl.com/shoulu/" target="_blank">网站快速收录</a><a href="https://www.cdcxhl.com/shoulu/" target="_blank">免费收录网站</a><a href="https://www.cdcxhl.com/service/guangdianxuke.html" target="_blank">广播电视节目制作许可证</a>            </div>
            <div class="fr ecode">
                <div class="fl">
                    <img src="/Public/Home/img/ewm.jpg">
                    <p>关注企业微信</p>
                </div>
                <div class="fr slogan">
                    <p class="icon">
                        <a class="ph" href=""><i class="iconfont"></i></a>
                        <a class="qq" href="tencent://message/?uin=1683211881&Site=&Menu=yes"><i class="iconfont"></i></a>
                    </p>
                    <p>
                        <i>想要找 </i> <a href="">小程序开发</a>、<a href="">APP开发</a>、
                        <a href="">营销型网站建设</a>、<a href="">网站建设</a>、
                        <i><a href="">网站定制开发</a></i> ,就选<a href="">创新互联</a>
                    </p>
                </div>
            </div>
        </div>
        <div class="bottom container">
            <p class="fl">
                版权所有:成都创新互联科技有限公司
                备案号:<a href="https://beian.miit.gov.cn/" target="_blank" rel="nofollow">蜀ICP备19037934号</a>
                服务热线:028-86922220
            </p>
            <p class="fr">
                <a href="https://www.cdxwcx.com/" target="_blank">成都网站建设</a>:
                <a href="https://www.cdcxhl.com/" target="_blank">创新互联</a>
            </p>
        </div>
    </div>
</footer>
<!--在线咨询-->
<div class="fot">
    <ul>
        <li>
            <a href="https://p.qiao.baidu.com/cps/mobileChat?siteId=11284691&userId=6256368&type=1&reqParam=%20{%22from%22:0,%22sessionid%22:%22%22,%22siteId%22:%2211284691%22,%22tid%22:%22-1%22,%22userId%22:%226256368%22,%22ttype%22:1,%22siteConfig%22:%20{%22eid%22:%226256368%22,%22queuing%22:%22%22,%22siteToken%22:%226ce441ff9e2d6bedbdfc2a4138de449e%22,%22userId%22:%226256368%22,%22isGray%22:%22false%22,%22wsUrl%22:%22wss://p.qiao.baidu.com/cps3/websocket%22,%22likeVersion%22:%22generic%22,%22siteId%22:%2211284691%22,%22online%22:%22true%22,%22webRoot%22:%22//p.qiao.baidu.com/cps3/%22,%22bid%22:%22160142915792139572%22,%22isSmallFlow%22:0,%22isPreonline%22:0,%22invited%22:0%20},%22config%22:%20{%22themeColor%22:%224d74fa%22%20}%20}&appId=&referer=&iswechat=0&expectWaiter=-1&openid=null&otherParam=null&telephone=null&speedLogId=null&eid=null&siteToken=6ce441ff9e2d6bedbdfc2a4138de449e" target="_blank">
                <img src="/Public/Home/img/fot1.png" alt="">
                <p>在线咨询</p>
            </a>
        </li>
        <li>
            <a href="tel:18980820575" target="_blank">
                <img src="/Public/Home/img/fot2.png" alt="">
                <p>拨打电话</p>
            </a>
        </li>
    </ul>
</div>
</body>
</html>
<script>
    $(".con img").each(function(){
        var src = $(this).attr("src");    //获取图片地址
        var str=new RegExp("http");
        var result=str.test(src);
        if(result==false){
            var url = "https://www.cdcxhl.com"+src;    //绝对路径
            $(this).attr("src",url);
        }
    });
    window.onload=function(){
        document.oncontextmenu=function(){
            return false;
        }
    }
</script>