设置传递格式:

request.setCharacterEncoding("utf-8");

中文字符解码:

import java.net.URLDecoder;

String format = URLDecoder.decode(request.getParameter("format"), "utf-8"); 

中文字符加码:

import java.net.URLEncoder;

String username = URLEncoder.encode(request.getParameter("username"), "UTF-8");

实例:

登陆后创建session:

<%@page import="java.net.*"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
</head>
<body>
<%
request.setCharacterEncoding("UTF-8"); String username = URLEncoder.encode(request.getParameter("username"), "UTF-8");
String password =URLEncoder.encode(request.getParameter("password"),"UTF-8") ; Cookie usernameCookie = new Cookie("username",username);
Cookie passwordCookie = new Cookie("password",password); response.addCookie(usernameCookie);
response.addCookie(passwordCookie); request.getRequestDispatcher("login_success.jsp").forward(request, response);
%> </body>
</html>

表单提交包含中文字符显示:

<%@page import="java.net.URLDecoder"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
</head>
<body> <%
request.setCharacterEncoding("UTF-8");
Cookie[] cookies = request.getCookies();
String username = "";
String password = ""; for(Cookie cookie : cookies) {
if("username".equals(cookie.getName()))
username =URLDecoder.decode(cookie.getValue(),"utf-8") ; if("password".equals(cookie.getName()))
password = cookie.getValue(); } %> <h1 align="center">恭喜<%=username %>登录成功</h1>
<hr>
<div style="border: solid 1px;">
<p> 用户名:<%=username %> </p>
<p> 密码: <%=password %> </p>
</div> </body>
</html>

最新文章

  1. [下载]北京新版小学英语五年级上册mp3点读APP
  2. Codeforces Round #284 (Div. 2)A B C 模拟 数学
  3. Java关键字——super
  4. Android MVVM框架RoboBinding初探
  5. poj 3335(半平面交)
  6. 现在有T1、T2、T3三个线程,怎样保证T2在T1执行完后执行,T3在T2执行完后执行?使用Join
  7. Windows Phone 8开发环境搭建
  8. iOS开发中打开本地应用、打开appStore应用、给app评分功能实现
  9. 浏览器开发 IE webkit chrome浏览器定制
  10. Android Studio的使用(十)--读取assets、Raw文件夹下文件,以及menu、drawable文件夹
  11. oracle 裸设备划分 --centos6.5
  12. 【代码笔记】Web-Javascript-Javascript函数
  13. Datatable数据转换成excel导出时 数值类型在EXCEL中为文本形式 无法进行统计
  14. Linux下批量ping某个网段ip的脚本
  15. String to Integer (atoi) leetcode java
  16. 虚拟机vmnet0、vmnet1和vmnet8的区别
  17. style和getComputedStyle(ff)和currentStyle
  18. MVC的项目部署成应用程序或虚拟目录路径的问题
  19. Ubuntu 定时任务
  20. 字符串连接比较(std::unique_ptr实现)

热门文章

  1. linux host=${host:-&quot;localhost&quot;}使用方法
  2. BAT网络运维常见面试题目总结
  3. 在 Linux 上如何清除内存的 Cache、Buffer 和交换空间
  4. VK Cup 2015 - Round 2 E. Correcting Mistakes —— 字符串
  5. selenium使用笔记(一)——selenium你该知道的
  6. java random配置修改
  7. 第三篇:python基础之数据类型与变量
  8. css 鼠标移入边框填充效果
  9. 搜索算法 pots
  10. hdu-5000 Clone(dp)