当前位置:网站首页>Servlet 乱码解决
Servlet 乱码解决
2022-07-21 19:27:00 【华为云】
可能存在的乱码的一些解决的办法
乱码的问题主要出现在tomcat8之前,但是目前的插件管理依赖只能到7。
我们还是用一个写的表单,然后写一个Servlet代码
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Title</title></head><body><form action="/jgdabc00" method="post"> <input type="text" name="username"> <input type="password" name="password"> <input type="checkbox" name="hobby" value="1">游泳 <input type="checkbox" name="hobby" value="2">爬山<br> <input type="submit"></form></body></html>
package jgd;import javax.servlet.ServletException;import javax.servlet.annotation.WebServlet;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import java.io.IOException;import java.util.Map;@WebServlet("/jgdabc00")public class ServletDemo10 extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {// super.doGet(req, resp);// Get请求逻辑 System.out.println("get---"); this.doPost(req,resp);// }// @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { System.out.println("post---");// 获取所有参数的map集合 Map<String, String[]> map = req.getParameterMap(); String queryString = req.getQueryString(); System.out.println(queryString); for (String key:map.keySet()) { System.out.print(key+":"); String[] values = map.get(key); //获取value for (String value:values) System.out.println(value+" "); }// 根据key获取参数值,数组 String[] hobbies = req.getParameterValues("hobby");// for(String hobby:hobbies){// System.out.println(hobby);// }// 根据key获取单个参数值 String password = req.getParameter("password"); System.out.println(password);// 等相同业务代码 }}
启动!
我们填入中文,提交。
这里出现了乱码。
边栏推荐
- 网页保存为pdf神器(可自定义编辑)—Print Edit WE
- 2022开源PHP留言反馈管理系统 v2.0
- Continuous improvement of software testing process
- The three-tier structure completes the addition, deletion, modification and search of chapter I
- 一些个人理解
- AtCoder Beginner Contest 260 E - At Least One
- Google Earth engine (GEE) - one day NDVI download of the simplest sentinel-2 image
- Laundry applet source code - add docking with third-party errands
- Energy principle and variational method note 10: virtual displacement principle
- 能量原理与变分法笔记02:变分问题 变分和微分运算能交换次序 欧拉方程
猜你喜欢
上门预约程序公众号模块 完美版
[微信小程序开发者工具] × #initialize-error: Error: ENOENT: no such file or directory, open
Std:: thread combined with class object
洗衣店小程序源码-增加对接第三方跑腿
2022 第三方宝塔面板 btcloud PHP源码
std::thread 與類對象結合
11 classification maintenance of commodity system in gulimall background management
Carbon 语言【中文入门教程】
史上最全的mysql数据类型汇总-(上)
动态新增、修改Logback的Appender(可实现动态调整日志级别,Appender参数)
随机推荐
day02-2
克服拖延症的7种最佳方法
el-table-column嵌套el-table-column ,多级表头横向滚动的bug
2022 third party pagoda panel btcloud PHP source code
leetcode刷题:动态规划02(爬楼梯)
【814. 二叉树剪枝】
Standard input / output stream
Door to door appointment procedure official account module perfect version
1307_ Summary of crystal oscillator test in embedded design
元宇宙时代到来,Soul张璐团队如何打造全新社交体验?
网页保存为pdf神器(可自定义编辑)—Print Edit WE
std::thread 与类对象结合
11 classification maintenance of commodity system in gulimall background management
How to add an operator in ONEFLOW
Request获取请求行数据和请求头数据
Google Earth engine (GEE) - one day NDVI download of the simplest sentinel-2 image
研发中台拆分过程的一些心得总结
【信息收集】从FoFa—API接口数据写入TXT和Excel
史上最全的mysql数据类型汇总(下)
jsonobject的get方法使用