请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

4-9 index.html放在webapp下面正常,放到WEB-INF里面后出现乱码

放到WEB-INF,通过后台访问乱码。之前都是好好的,没出现这个情况

http://localhost:8080/o2o/shopadmin/shopoperation

https://img1.sycdn.imooc.com//szimg/5af7c8be0001043f13090577.jpg

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

插入代码

1回答

翔仔 2018-05-13 16:14:25

同学好,乱码就是由于编码不一致造成的,请检查你的spring-web.xml里面设置的utf-8

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
    <!-- 配置SpringMVC -->
    <!-- 1.开启SpringMVC注解模式 -->
    <mvc:annotation-driven />
 
    <!-- 2.静态资源默认servlet配置 (1)加入对静态资源的处理:js,gif,png (2)允许使用"/"做整体映射 -->
    <mvc:resources mapping="/resources/**" location="/resources/" />
    <mvc:default-servlet-handler />
 
    <!-- 3.定义视图解析器 -->
    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/html/"></property>
        <property name="suffix" value=".html"></property>
    </bean>
    <!-- 文件上传解析器 -->
    <bean id="multipartResolver"
        class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <property name="defaultEncoding" value="utf-8"></property>
        <!-- 1024 * 1024 * 20 = 20M -->
        <property name="maxUploadSize" value="20971520"></property>
        <property name="maxInMemorySize" value="20971520"></property>
    </bean>
 
    <!-- 4.扫描web相关的bean -->
    <context:component-scan base-package="com.imooc.o2o.web" />
</beans>

还有html里面utf8

shoperation.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>SUI Mobile Demo</title>
<meta name="description"
    content="MSUI: Build mobile apps with simple HTML, CSS, and JS components.">
<meta name="author" content="阿里巴巴国际UED前端">
<meta name="viewport" content="initial-scale=1, maximum-scale=1">
<link rel="shortcut icon" href="/favicon.ico">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="format-detection" content="telephone=no">
 
<!-- Google Web Fonts -->
 
<link rel="stylesheet"
    href="//g.alicdn.com/msui/sm/0.6.2/css/sm.min.css">
<link rel="stylesheet"
    href="//g.alicdn.com/msui/sm/0.6.2/css/sm-extend.min.css">
 
<link rel="apple-touch-icon-precomposed"
    href="/assets/img/apple-touch-icon-114x114.png">
 
</head>
<body>
    <div class="page-group">
        <div id="page-label-input" class="page">
            <header class="bar bar-nav">
                <a class="button button-link button-nav pull-left back"
                    href="/demos/form"> <span class="icon icon-left"></span> 返回
                </a>
                <h1 class="title">商店信息</h1>
            </header>
            <div class="content">
                <div class="list-block">
                    <ul>
                        <!-- Text inputs -->
                        <li>
                            <div class="item-content">
                                <div class="item-inner">
                                    <div class="item-title label">商铺名称</div>
                                    <div class="item-input">
                                        <input type="text" id="shop-name" placeholder="商铺名称">
                                    </div>
                                </div>
                            </div>
                        </li>
                        <!-- 商铺分类 下拉列表 -->
                        <li>
                            <div class="item-content">
                                <div class="item-inner">
                                    <div class="item-title label">商铺分类</div>
                                    <div class="item-input">
                                        <select id="shop-category">
                                        </select>
                                    </div>
                                </div>
                            </div>
                        </li>
                        <!-- 区域分类 下拉列表 -->
                        <li>
                            <div class="item-content">
                                <div class="item-inner">
                                    <div class="item-title label">所属区域</div>
                                    <div class="item-input">
                                        <select id="area">
                                        </select>
                                    </div>
                                </div>
                            </div>
                        </li>
                        <!-- 详细地址 text -->
                        <li>
                            <div class="item-content">
                                <div class="item-inner">
                                    <div class="item-title label">详细地址</div>
                                    <div class="item-input">
                                        <input type="text" id="shop-addr" placeholder="详细地址">
                                    </div>
                                </div>
                            </div>
                        </li>
                        <!-- 联系电话 text -->
                        <li>
                            <div class="item-content">
                                <div class="item-inner">
                                    <div class="item-title label">联系电话</div>
                                    <div class="item-input">
                                        <input type="text" id="shop-phone" placeholder="联系电话">
                                    </div>
                                </div>
                            </div>
                        </li>
                        <!-- 缩略图 上传控件 -->
                        <li>
                            <div class="item-content">
                                <div class="item-inner">
                                    <div class="item-title label">缩略图</div>
                                    <div class="item-input">
                                        <input type="file" id="shop-img">
                                    </div>
                                </div>
                            </div>
                        </li>
                        <!-- 店铺简介 textarea -->
                        <li class="align-top">
                            <div class="item-content">
                                <div class="item-inner">
                                    <div class="item-title label">店铺简介</div>
                                    <div class="item-input">
                                        <textarea id="shop-desc" placeholder="店铺简介"></textarea>
                                    </div>
                                </div>
                            </div>
                        </li>
                        <!-- 验证码 ka -->
                        <li>
                            <div class="item-content">
                                <div class="item-inner">
                                    <div class="item-title label">验证码</div>
                                    <input type="text" id="j_captcha" placeholder="验证码">
                                    <div class="item-input">
                                        <img id="captcha_img" alt="点击更换" title="点击更换"
                                            onclick="changeVerifyCode(this)" src="../Kaptcha" />
                                    </div>
                                </div>
                            </div>
                        </li>
                    </ul>
                </div>
                <div class="content-block">
                    <div class="row">
                        <div class="col-50">
                            <a href="/o2o/shopadmin/shopmanagement" class="button button-big button-fill button-danger">返回</a>
                        </div>
                        <div class="col-50">
                            <a href="#" class="button button-big button-fill button-success"
                                id="submit">提交</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
 
    </div>
    <script type='text/javascript'
        src='//g.alicdn.com/sj/lib/zepto/zepto.min.js' charset='utf-8'></script>
    <script type='text/javascript'
        src='//g.alicdn.com/msui/sm/0.6.2/js/sm.min.js' charset='utf-8'></script>
    <script type='text/javascript'
        src='//g.alicdn.com/msui/sm/0.6.2/js/sm-extend.min.js' charset='utf-8'></script>
    <script type='text/javascript' src='../resources/js/common/common.js'
        charset='utf-8'></script>
    <script type='text/javascript'
        src='../resources/js/shop/shopoperation.js' charset='utf-8'></script>
</body>
</html>


0 回复 有任何疑惑可以回复我~
  • 提问者 l00ker #1
    还是没用,我把老师的代码复制进去。还是一样。。。在之前都没有这样的。html在webapp里面都是正常的,移到WEB-INF才出现乱码
    回复 有任何疑惑可以回复我~ 2018-05-13 19:31:56
  • 提问者 l00ker #2
    把sjopoperation.html移到webapp下面,直接访问。正常,不乱码。那应该不是html的问题,spring-web直接复制的老师的。那是哪里的问题了
    回复 有任何疑惑可以回复我~ 2018-05-13 19:41:01
  • 翔仔 回复 提问者 l00ker #3
    同学好,建议逐步排查一下,肯定是哪里配置错了,我这边的还有别的同学也是没有问题的,遇到问题得慢慢定位排查,不要觉得之前没问题了之后就被卡住了。你可以从chrome的开发者工具里面调试一下,并且从后台调试一下,看看数据返回前端的时候是否已经乱码了,还是说到了前端才乱码。前端乱码的话看看network里面的请求头和返回头,看看当时的编码,不清楚的话可以百度一下,顺便锻炼一下自己处理问题的能力,总之就是编码不一致造成的:)
    回复 有任何疑惑可以回复我~ 2018-05-13 21:56:34
问题已解决,确定采纳
还有疑问,暂不采纳
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号