SSM中jsp向后台Controller传值中文乱码的奇葩解决!!!

场景

进行简单的SSM整合时,jsp提交用户名到后台Controller时,插入数据时显示中文乱码。

然后,log4j配置输出sql语句,看到sql语句执行插入时,值就已经是乱码了。

关于log4j配置输出sql语句,参照:

https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/85159383

说明在插入数据库之前就已经乱码了。

然后在Controller中打断点,可以看到在jsp传递过来时就已经是乱码了。

然后查看jsp页面设置

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

加了!!!

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

  加了!!

解决

在使用bootstrap的模板时,直接将其表单复制过来,添加了action属性,没加method属性为post!!!!!!

<form action="addUser" method="post">
  <div class="form-group">
    <label for="name">用户名</label>
    <input type="text" class="form-control" id="name" name ="name" placeholder="name">
  </div>
  <div class="form-group">
    <label for="age">年龄</label>
    <input type="number" class="form-control" id="age"  name="age" placeholder="age">
  </div>
  <button type="submit" class="btn btn-default">新增用户</button>
</form>

将method改为post好了!!!!

猜你喜欢

转载自blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/85160598