【发布时间】:2015-07-17 15:49:40
【问题描述】:
在您将我的问题标记为与this 问题重复之前,我想说我已阅读它以及此post。
但是,我做错了,我继续以错误的格式从我的 jsp 中的表单中读取数据(使用 POST 方法)。我做了什么:
1.在我的 JSP 中,我把这个
<%@page contentType="text/html" pageEncoding="UTF-8" language="java" %>
在标题中这个<meta charset="UTF-8">
2.在servlet中
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//...
//code
//...
request.setCharacterEncoding("UTF-8");
/*if (request.getCharacterEncoding() == null) {
request.setCharacterEncoding("UTF-8");
}
*/
//...
//code
//...
s1 = request.getParameter(kname1); //<-here I read the value from the JSP and get finally this ÎÏδÏαδαÏ
}
3. 在 web.xml 我有<?xml version="1.0" encoding="UTF-8"?>
我在这里错过了什么??
【问题讨论】:
-
试试这个:
s1 = new String(request.getParameter(kname1).getBytes(),"utf-8"); -
也打印这个:
request.getParameter(kname1).getBytes();,那么你可以从字节中找出问题所在。 (删除if (request.getCharacterEncoding() == null) { request.setCharacterEncoding("UTF-8"); } -
您要发布表格吗?
kname1应该在正文中还是在查询字符串中? -
@SotiriosDelimanolis
kname1是一个字符串变量。我正在尝试阅读一个希腊词... @nafas 我有一点改进。从这个 ÎÏδÏÎ±Î´Î±Ï 现在我得到 α�?δα�?δ 。在日志中我得到 [B@24803429 -
我问它是从哪里来的?
标签: java jsp servlets encoding utf-8