网站建设资讯

NEWS

网站建设资讯

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>
            文章位置:<a href="http://scjierui.cn/article/psidcp.html">http://scjierui.cn/article/psidcp.html</a>
        </div>
    </div>
    <div class="other">
        <h3>其他资讯</h3>
        <ul>
            <li>
                    <a href="/article/dsjiiij.html">c语言函数声明最简单方法 c语言 函数声明</a>
                </li><li>
                    <a href="/article/dsjiiej.html">linux命令大全速查 linux 命令速查手册</a>
                </li><li>
                    <a href="/article/dsjiigh.html">交换机路由器连接 交换机路由器连接示意图</a>
                </li><li>
                    <a href="/article/dsjiiei.html">sap系统清理废品的简单介绍</a>
                </li><li>
                    <a href="/article/dsjiieg.html">linux开始另一个命令 linux开机启动切换命令行</a>
                </li>        </ul>
    </div>
</div>
</div>
<footer>
    <div class="footop">
        <div class="wrap">
            <div class="bottomrpw">
                <div class="erp arp">
                    <dl>
                        <dt>ADDRESS</dt>
                        <dd class="address"> <i class="icon"></i> <span class="word">成都市青羊区锦天国际1号楼1002室</span> </dd>
                    </dl>
                </div>
                <div class="erp arp">
                    <dl>
                        <dt>TEL</dt>
                        <dd class="phonum"> <i class="icon"></i> <span class="word en"> <a href="tel:18980820575">18980820575</a> </span> </dd>
                    </dl>
                </div>
                <div class="erp crp">
                    <dl>
                        <dt>OTHER</dt>
                        <dd> <a class="word get-quote">获得报价与方案</a> </dd>
                        <dd> <a href="#" target="_blank" rel='nofollow' class="word" title="付款方式">付款方式</a> </dd>
                    </dl>
                </div>
                <div class="erp code-rp">
                    <dl>
                        <dt>Wechat</dt>
                        <dd class="code-wrap"> <span class="code"> <img src="/Public/Home/images/qr-code.jpg" alt="美图齐众微信公众号" /> </span> </dd>
                    </dl>
                </div>
            </div>
        </div>
    </div>
    <div class="footerbot">
        <div class="friendlinks">
            <div class="wrap">
                <ul class="rpl">
                    <li><a href="http://www.cdkjz.cn/small/" title="成都微信小程序开发" target="_blank">成都微信小程序开发</a></li><li><a href="http://seo.cdcxhl.cn/wztg/" title="成都谷歌SEO" target="_blank">成都谷歌SEO</a></li><li><a href="http://www.swwzsj.com/" title="成都精神堡垒定制" target="_blank">成都精神堡垒定制</a></li><li><a href="http://www.sczitong.cn/" title="梓潼网站建设" target="_blank">梓潼网站建设</a></li><li><a href="http://www.tyanhua.com" title="成都发光字制作公司" target="_blank">成都发光字制作公司</a></li><li><a href="https://www.cdxwcx.com/" title="成都网络公司" target="_blank">成都网络公司</a></li><li><a href="http://www.hfjike.com/" title="网站改版维护" target="_blank">网站改版维护</a></li><li><a href="http://www.shengjin119.com/" title="胜锦安防科技" target="_blank">胜锦安防科技</a></li><li><a href="http://www.cdkjz.cn/develop/" title="电商网站" target="_blank">电商网站</a></li><li><a href="http://www.hongxinsd.com/" title="成都喷绘设计" target="_blank">成都喷绘设计</a></li>                </ul>
            </div>
        </div>
        <div class="wrap">
            <div class="copyright"> <span class="en">©2025</span> 青羊区美图齐众设计工作室(个体工商户)四川站<span class="en">ALL RIGHTS
                        RESERVED.</span> <a rel="nofollow" href="https://beian.miit.gov.cn" target="_blank">蜀ICP备2025119604号-2</a> </div>
        </div>
    </div>
</footer>
<div class="fcwrap">
    <ul class="rpl clearfix">
        <li class="phone"> <a rel="nofollow" target="_blank" href="tel:18980820575"> <i class="icon"></i>
            <strong>18980820575</strong> </a> </li>
        <li class="qq"> <a rel="nofollow" target="_blank"
                           href="https://wpa.qq.com/msgrd?v=1&uin=244261566&site=qq&menu=yes"> <i class="icon"></i>
            <strong>244261566</strong> </a> </li>
        <li class="back-top"> <a href="javascript:void(0)" rel="nofollow" class="back-to-top"> <i class="icon"></i>
            <strong>回到顶部</strong> </a> </li>
    </ul>
</div>
<!--nav-->
<div class="n-Wrap">
    <div class="navBar visble show">
        <div class="barlogo">
            <a href="/" rel="nofollow">
                <img src="/Public/Home/images/logo1.png" alt="四川做网站" />
                <img src="/Public/Home/images/logo2.png" alt="四川网站设计" />
            </a>
        </div>
        <div class="bmenu">
            <i class="bar-top"><span></span></i>
            <i class="bar-cen"><span></span></i>
            <i class="bar-bom"><span></span></i>
            <i class="bar-left"><span></span></i>
            <i class="bar-right"><span></span></i>
        </div>
    </div>
    <section class="fixmenu">
        <div class="close-bar">
            <i class="bar-left"><span></span></i>
            <i class="bar-right"><span></span></i>
        </div>
        <nav class="smph">
            <ul>
                <li class="index-hrefs on"><a href="http://www.scjierui.cn/"><font>首页</font></a></li>
                <li><a href="/about/" rel="nofollow"><font>关于美图齐众</font></a></li>
                <li><a href="/service/" rel="nofollow"><font>服务范围</font></a></li>
                <li><a href="/case/" rel="nofollow"><font>案例展示</font></a></li>
                <li><a href="/solve/" rel="nofollow"><font>解决方案</font></a></li>
                <li><a href="/news/" rel="nofollow"><font>建站资讯</font></a></li>
                <li><a href="/contact/" rel="nofollow"><font>联系美图齐众</font></a></li>
            </ul>
            <div class="pwrap">
                <span class="label">服务热线</span>
                <strong class="phone"><a href="tel:18980820575">18980820575</a></strong>
            </div>
        </nav>
    </section>
</div>
<!--end nav-->
<script src="/Public/Home/js/hotcss.js"></script>
<script type="text/javascript" src="/Public/Home/js/su_new.js"></script>
</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>