jsp页面乱码?

正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

7回答
提问者 慕丘 2019-10-11 12:06:47

悲催啊,还是不行,控制台打印的代码如下:

十月 11, 2019 12:02:35 下午 org.apache.coyote.AbstractProtocol init

信息: Initializing ProtocolHandler ["http-bio-8080"]

十月 11, 2019 12:02:35 下午 org.apache.coyote.AbstractProtocol init

信息: Initializing ProtocolHandler ["ajp-bio-8009"]

十月 11, 2019 12:02:35 下午 org.apache.catalina.startup.Catalina load

信息: Initialization processed in 327 ms

十月 11, 2019 12:02:35 下午 org.apache.catalina.core.StandardService startInternal

信息: Starting service Catalina

十月 11, 2019 12:02:35 下午 org.apache.catalina.core.StandardEngine startInternal

信息: Starting Servlet Engine: Apache Tomcat/7.0.96

十月 11, 2019 12:02:36 下午 org.apache.catalina.util.SessionIdGeneratorBase createSecureRandom

警告: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [675] milliseconds.

十月 11, 2019 12:02:36 下午 org.apache.catalina.startup.HostConfig deployDirectory

信息: Deploying web application directory D:\apache-tomcat-7.0.96\webapps\docs

十月 11, 2019 12:02:36 下午 org.apache.catalina.startup.HostConfig deployDirectory

信息: Deployment of web application directory D:\apache-tomcat-7.0.96\webapps\docs has finished in 52 ms

十月 11, 2019 12:02:36 下午 org.apache.catalina.startup.HostConfig deployDirectory

信息: Deploying web application directory D:\apache-tomcat-7.0.96\webapps\examples

十月 11, 2019 12:02:36 下午 org.apache.catalina.core.ApplicationContext log

信息: ContextListener: contextInitialized()

十月 11, 2019 12:02:36 下午 org.apache.catalina.core.ApplicationContext log

信息: SessionListener: contextInitialized()

十月 11, 2019 12:02:36 下午 org.apache.catalina.core.ApplicationContext log

信息: ContextListener: attributeAdded('StockTicker', 'async.Stockticker@1e27dc4')

十月 11, 2019 12:02:36 下午 org.apache.catalina.core.ApplicationContext log

信息: ContextListener: attributeAdded('org.apache.jasper.compiler.TldLocationsCache', 'org.apache.jasper.compiler.TldLocationsCache@8064a9')

十月 11, 2019 12:02:36 下午 org.apache.catalina.startup.HostConfig deployDirectory

信息: Deployment of web application directory D:\apache-tomcat-7.0.96\webapps\examples has finished in 161 ms

十月 11, 2019 12:02:36 下午 org.apache.catalina.startup.HostConfig deployDirectory

信息: Deploying web application directory D:\apache-tomcat-7.0.96\webapps\host-manager

十月 11, 2019 12:02:36 下午 org.apache.catalina.startup.HostConfig deployDirectory

信息: Deployment of web application directory D:\apache-tomcat-7.0.96\webapps\host-manager has finished in 39 ms

十月 11, 2019 12:02:36 下午 org.apache.catalina.startup.HostConfig deployDirectory

信息: Deploying web application directory D:\apache-tomcat-7.0.96\webapps\manager

十月 11, 2019 12:02:36 下午 org.apache.catalina.startup.HostConfig deployDirectory

信息: Deployment of web application directory D:\apache-tomcat-7.0.96\webapps\manager has finished in 37 ms

十月 11, 2019 12:02:36 下午 org.apache.catalina.startup.HostConfig deployDirectory

信息: Deploying web application directory D:\apache-tomcat-7.0.96\webapps\ROOT

十月 11, 2019 12:02:36 下午 org.apache.catalina.startup.HostConfig deployDirectory

信息: Deployment of web application directory D:\apache-tomcat-7.0.96\webapps\ROOT has finished in 32 ms

十月 11, 2019 12:02:36 下午 org.apache.coyote.AbstractProtocol start

信息: Starting ProtocolHandler ["http-bio-8080"]

十月 11, 2019 12:02:36 下午 org.apache.coyote.AbstractProtocol start

信息: Starting ProtocolHandler ["ajp-bio-8009"]

十月 11, 2019 12:02:36 下午 org.apache.catalina.startup.Catalina start

信息: Server startup in 1416 ms

aaa:123

十月 11, 2019 12:02:43 下午 com.mchange.v2.log.MLog <clinit>

信息: MLog clients using java 1.4+ standard logging.

十月 11, 2019 12:02:43 下午 com.mchange.v2.c3p0.C3P0Registry banner

信息: Initializing c3p0-0.9.1.2 [built 21-May-2007 15:04:56; debug? true; trace: 10]

十月 11, 2019 12:02:43 下午 com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource getPoolManager

信息: Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, dataSourceName -> 1hge15xa51fbqrz8ka5lxh|375c2a, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> com.mysql.jdbc.Driver, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 1hge15xa51fbqrz8ka5lxh|375c2a, idleConnectionTestPeriod -> 0, initialPoolSize -> 3, jdbcUrl -> jdbc:mysql:///shop?useUnicode=true&characterEncoding=UTF8, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 0, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 15, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 3, numHelperThreads -> 3, numThreadsAwaitingCheckoutDefaultUser -> 0, preferredTestQuery -> null, properties -> {user=******, password=******}, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false ]

[Category [cid=1, cname=人物画, cdesc=描述人物的画], Category [cid=2, cname=风景画, cdesc=风景画], Category [cid=3, cname=动物画, cdesc=描述动物的画]]


  • 同学你好。同学是只有这一个页面乱码吗?还是只要点击了一次分类列表以后再点击别的页面也是乱码呢?祝学习愉快~
    2019-10-11 16:09:30
芝芝兰兰 2019-10-11 10:22:55

同学你好。可以尝试以下几步:

1、先清除缓存

1)将Tomcat停下,将曾经add进去的项目重新remove出来,然后在Tomcat上右键选择clean...

2)在Eclipse的头部导航中选择Project->clean... 

3)然后在浏览器中使用Ctrl+Shift+Delete 清除缓存。将项目重新add到Tomcat中重启项目 


2、在Chrome浏览器内的乱码页面上右键,选择查看网页源代码,或者使用快捷键Ctrl+U。看一下里面的编码方式是否为utf-8。


3、如果除了这个链接,其他都不乱码,把这个页面备份一下,删除后重新建一个jsp,然后把之前内容拷贝过来后保存。


如果解答了同学的疑问,望采纳~

祝学习愉快~

提问者 慕丘 2019-10-10 19:11:16
  • 同学你好。同学使用的是Eclipse自带的浏览器呢,同学使用Chrome浏览器访问一下看看是否会有问题呢?祝学习愉快~
    2019-10-10 19:23:34
  • 提问者 慕丘 回复 芝芝兰兰 #2
    使用Chrome浏览器也是一样
    2019-10-10 21:05:48
芝芝兰兰 2019-10-10 19:01:01

同学你好,控制台输出的list内容不是乱码的话,证明从数据库查询的数据不是乱码呢~同学可以尝试在下面红框位置添加一下字符编码过滤试试:

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

http://img1.sycdn.imooc.com//climg/5d9f0deb09bc9ad114890836.jpg

如果还是不行,请将项目目录都展开截图下~并附一下web.xml和Servlet的代码

祝学习愉快~

  • 提问者 慕丘 #1
    老师,添加了还是不行,只要点击了分类列表就会乱码
    2019-10-10 19:08:25
提问者 慕丘 2019-10-10 18:07:44

<%@ page language="java" contentType="text/html; charset=UTF-8"

pageEncoding="UTF-8"%>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>


<!DOCTYPE html>

<html>



<!-- Mirrored from admindesigns.com/demos/absolute/1.1/admin_forms-validation.html by HTTrack Website Copier/3.x [XR&CO'2014], Thu, 06 Aug 2015 02:56:15 GMT -->

<head>

<!-- Meta, title, CSS, favicons, etc. -->

<meta charset="utf-8">


<title>油画商城--分类列表</title>


<link rel="stylesheet" type="text/css"

href="${pageContext.request.contextPath }/assets/skin/default_skin/css/theme.css">

<link rel="stylesheet" type="text/css"

href="${pageContext.request.contextPath }/assets/admin-tools/admin-forms/css/admin-forms.css">

<link rel="shortcut icon"

href="${pageContext.request.contextPath }/assets/img/favicon.ico">

</head>


<body class="admin-validation-page" data-spy="scroll"

data-target="#nav-spy" data-offset="200">

<div id="main">

<%@ include file="header.jsp"%>


<%@ include file="left.jsp"%>


<section id="content_wrapper">

<section id="content" class="table-layout animated fadeIn">

<div class="tray tray-center">

<div class="content-header">

<h2>分类列表</h2>

<p class="lead"></p>

</div>

<div class="admin-form theme-primary mw1000 center-block"

style="padding-bottom: 175px;">

<div class="panel  heading-border">

<div class="panel-menu">

<div class="row">

<div class="hidden-xs hidden-sm col-md-3">

<div class="btn-group">

<button type="button" class="btn btn-default light">

<i class="fa fa-refresh"></i>

</button>

<button type="button" class="btn btn-default light">

<i class="fa fa-trash"></i>

</button>

<button type="button" class="btn btn-default light">

<i class="fa fa-plus"

onclick="javascript:window.location.href='/employee/to_add';"></i>

</button>

</div>

</div>

<div class="col-xs-12 col-md-9 text-right">

<div class="btn-group">

<button type="button" class="btn btn-default light">

<i class="fa fa-chevron-left"></i>

</button>

<button type="button" class="btn btn-default light">

<i class="fa fa-chevron-right"></i>

</button>

</div>

</div>

</div>

</div>

<div class="panel-body pn">

<table id="message-table"

class="table admin-form theme-warning tc-checkbox-1">

<thead>

<tr class="">


<th class="hidden-xs">名称</th>


<th class="hidden-xs">描述</th>

<th>操作</th>

</tr>

</thead>

<tbody>

<c:forEach var="category" items="${list}">

<tr class="message-unread">

<td>${category.cname}</td>


<td>${category.cdesc}</td>

<td><a href="#">编辑</a> <a href="#">删除</a></td>

</tr>

</c:forEach>

</tbody>

</table>

</div>

</div>

</div>

</div>

</section>


</section>

</div>

<style>

/* demo page styles */

body {

min-height: 2300px;

}


.content-header b, .admin-form .panel.heading-border:before, .admin-form .panel .heading-border:before

{

transition: all 0.7s ease;

}

/* responsive demo styles */

@media ( max-width : 800px) {

.admin-form .panel-body {

padding: 18px 12px;

}

}

</style>


<style>

.ui-datepicker select.ui-datepicker-month, .ui-datepicker select.ui-datepicker-year

{

width: 48%;

margin-top: 0;

margin-bottom: 0;

line-height: 25px;

text-indent: 3px;

color: #888;

border-color: #DDD;

background-color: #FDFDFD;

-webkit-appearance: none; /*Optionally disable dropdown arrow*/

}

</style>

<script

src="${pageContext.request.contextPath }/vendor/jquery/jquery-1.11.1.min.js"></script>

<script

src="${pageContext.request.contextPath }/vendor/jquery/jquery_ui/jquery-ui.min.js"></script>

<script

src="${pageContext.request.contextPath }/assets/admin-tools/admin-forms/js/jquery.validate.min.js"></script>

<script

src="${pageContext.request.contextPath }/assets/admin-tools/admin-forms/js/additional-methods.min.js"></script>

<script

src="${pageContext.request.contextPath }/assets/admin-tools/admin-forms/js/jquery-ui-datepicker.min.js"></script>

<script

src="${pageContext.request.contextPath }/assets/js/utility/utility.js"></script>

<script

src="${pageContext.request.contextPath }/assets/js/demo/demo.js"></script>

<script src="${pageContext.request.contextPath }/assets/js/main.js"></script>

<script type="text/javascript"

src="${pageContext.request.contextPath }/js/pages.js"></script>

<script type="text/javascript"

src="${pageContext.request.contextPath }/js/items.js"></script>

</body>

</html>


好帮手慕阿满 2019-10-07 17:58:16

同学你好,问一下同学jsp页面中有乱码吗?如果有,建议同学复制源码中的页面替换一下。另外建议同学在链接数据库时,加上useUnicode=true&characterEncoding=UTF8,如:

http://img1.sycdn.imooc.com//climg/5d9b0c2c09ff04dd12160138.jpg

如果我的回答解决了你的疑惑,请采纳。祝:学习愉快~

  • 提问者 慕丘 #1
    不管是复制源码还是在连接数据库时加上那条语句,还是一样会乱码
    2019-10-07 18:18:10
  • 提问者 慕丘 #2
    登录进去就不会乱码,但是一点击分类列表就全乱码了
    2019-10-07 18:20:19
  • 好帮手慕珊 回复 提问者 慕丘 #3
    你好!可以把查询的数据输出到控制台,看一下是否乱码。另外,请把乱码的jsp页面贴出来,我们试一下。贴到回答里,不要贴到回复里,否则会失去格式。祝学习愉快!
    2019-10-08 09:38:00
好帮手慕柯南 2019-10-06 15:06:07

同学你好!

同学在页面是否指定了编码格式呢

http://img1.sycdn.imooc.com//climg/5d99923f0974308808750333.jpg

如果我的回答解决了你的疑惑,请采纳,祝学习愉快~

  • 提问者 慕丘 #1
    页面有指定编码格式啊
    2019-10-07 16:17:00
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师