【发布时间】:2017-05-05 10:14:08
【问题描述】:
我正在将 مرحبا 字符从 JSP 发送到 servlet,并且在 servlet 中我以这种格式 ÙØ±ØØØØ§ 接收字符。我想知道哪个正在转换这个以及他们正在使用哪个编码。
如果我在 POST 方法中传递这些字符,我将按原样接收数据。
我使用的是 JDK 1.6、Tomcat 7。
这是 JSP。
<%@page language="java" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Insert title here</title></head><body><form method="get" action="register">
Name:<input type="text" name="userName"/><br/><br/>
<input type="submit" value="SUBMIT"/>
</form></body></html>
这是 servlet。
public class Register extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
System.out.println("System: file.endcoding=" + System.getProperty("file.encoding"));
String str= request.getParameter("userName").trim();
RequestDispatcher rd = request.getRequestDispatcher("Display.jsp");
System.out.println("before encoding and decoding the string : "+str);
request.setAttribute("beforeconvert",str);}catch(Exception e){}}
【问题讨论】:
-
文件 file = new File(str); InputStreamReader r = new InputStreamReader(new FileInputStream(file)); System.out.println("接收字符串的编码:"+r.getEncoding());
-
你最好把你发送和接收的sn-p贴出来。