我的myeclpse能设置成UTF-8的地方全设置成UTF-8了,html是这么写的:
<html> <head>
<meta charset="UTF-8">
<meta name="content-type" content="text/html; charset=UTF-8">
<title>regist.html</title>
<meta name="keywords" content="keyword1,keyword2,keyword3">
<meta name="description" content="this is my page">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">--> </head>
<body>
<form action="/Practice/RequestDemo1">
用户名:<input type="text" name="username">
密码:<input type="password" name="password">
验证码:<input type="text" name="verifycode">
<input type="submit" value="提交并注册">
</form>
</body>
</html>通过request取数据是这么写的:public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
System.out.println("用户名"+request.getParameter("username"));
System.out.println("密码"+request.getParameter("password"));
System.out.println("验证码"+request.getParameter("verifycode"));然后打印到控制台从浏览器那边提交过来的中文就都是乱码了
<html> <head>
<meta charset="UTF-8">
<meta name="content-type" content="text/html; charset=UTF-8">
<title>regist.html</title>
<meta name="keywords" content="keyword1,keyword2,keyword3">
<meta name="description" content="this is my page">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">--> </head>
<body>
<form action="/Practice/RequestDemo1">
用户名:<input type="text" name="username">
密码:<input type="password" name="password">
验证码:<input type="text" name="verifycode">
<input type="submit" value="提交并注册">
</form>
</body>
</html>通过request取数据是这么写的:public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
System.out.println("用户名"+request.getParameter("username"));
System.out.println("密码"+request.getParameter("password"));
System.out.println("验证码"+request.getParameter("verifycode"));然后打印到控制台从浏览器那边提交过来的中文就都是乱码了
解决方案 »
- java 关于构造方法的题
- quartz的定时功能在windows下有效,在linux下无效
- myeclipse6.5里preferences有选择时区还是时间的选项吗?
- weblogic 命令行配置工具
- 弱问关于JAVA调用Web Service的一个问题
- 怎么求session会话活动时间
- 一个奇怪的问题,大家帮我分析下?
- 有重庆HP的兄弟没有,你门的待遇是多少啊
- bean使用问题
- struts2 在include的jsp中使用ognl
- HBuilder中出现Unhandled event loop exception java.lang.StackOverflowError这样的提示语
- shiro登录页面 显示404
默认 是 get方法 传到后台会存在乱码
需设置 属性 <form action="/Practice/RequestDemo1" method="post">
把这段代码写到doPost里面request.setCharacterEncoding("UTF-8");
System.out.println("用户名"+request.getParameter("username"));
System.out.println("密码"+request.getParameter("password"));
System.out.println("验证码"+request.getParameter("verifycode"));
可以进入tomcat修改server.xml加上这个URIEncoding="UTF-8"。
<Connector URIEncoding="UTF-8" connectionTimeout="20000" port="8080" protocol="org.apache.coyote.http11.Http11NioProtocol" redirectPort="8443"/>
如果实在还是解决不了,就把需要中文传参的地方进行encodeURIcomponent后台接收的地方进行 URLEncoder.decode