博客
关于我
Spring MVC 中文乱码问题解决
阅读量:613 次
发布时间:2019-03-12

本文共 888 字,大约阅读时间需要 2 分钟。

Spring MVC 中文乱码问题解决

表单提交controller获得中文参数后乱码解决方案:

  1. jsp页面编码设置为UTF-8
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
  1. form表单提交方式为必须为post,get方式下面spring编码过滤器不起效果
loginName:
password:
province:
city:
  1. 修改web.xml,增加编码过滤器,如下(注意,需要设置forceEncoding参数值为true)
characterEncodingFilter
org.springframework.web.filter.CharacterEncodingFilter
encoding
UTF-8
forceEncoding
true
characterEncodingFilter
/*
  • 这里需要注意的是,最好把这段代码放在web.xml中开头的位置,因为拦截有顺序,如果放在后面的话容易拦截不到。
  1. 右键点击项目名,点击Properties看你项目的编码是否UTF-8,不是就改为UTF-8

在这里插入图片描述

  1. 可以配置eclipse的全局编码为UTF-8,这样你新建,导入项目都会默认设为UTF-8,
    在eclipse中点击window–>preferences–>general–>workspace设置编码为UTF-8
    在这里插入图片描述

转载地址:http://wchxz.baihongyu.com/

你可能感兴趣的文章
NO 157 去掉禅道访问地址中的zentao
查看>>
no available service ‘default‘ found, please make sure registry config corre seata
查看>>
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
查看>>
no connection could be made because the target machine actively refused it.问题解决
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>
No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
查看>>
No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
查看>>
No module named 'crispy_forms'等使用pycharm开发
查看>>
No module named cv2
查看>>
No module named tensorboard.main在安装tensorboardX的时候遇到的问题
查看>>
No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
查看>>
No new migrations found. Your system is up-to-date.
查看>>
No qualifying bean of type XXX found for dependency XXX.
查看>>
No qualifying bean of type ‘com.netflix.discovery.AbstractDiscoveryClientOptionalArgs<?>‘ available
查看>>
No resource identifier found for attribute 'srcCompat' in package的解决办法
查看>>
no session found for current thread
查看>>
no such file or directory AndroidManifest.xml
查看>>
No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android
查看>>