2011-04-18 110 views
0

我有一个代码,在我的Java方面:Htaccess更改页面的内容类型?

.... 
PrintWriter writer = response.getWriter(); 
response.setContentType("application/json; charset=utf-8"); 
response.setCharacterEncoding("UTF-8"); 
.... 

我使用Struts2的,JSP和Java我的应用程序对MySQL和Apache。当我写的东西,以响应对象,并在萤火检查内容类型总是

charset=ISO-8859-1 

所以,当我想通过响应对象写的东西没有出现无法识别的字符。

我的jsp文件具有该行起初每次:

<%@ page contentType="text/html;charset=UTF-8" language="java" %> 

我测试了一个程序,它工作时没有越过的.htaccess一切正常。我知道.htaccess更改内容类型。

我想是这样的位置:

http://www.askapache.com/htaccess/setting-charset-in-htaccess.html

但是我不知道我错过了什么,或者尝试别的什么吗?

回答

0

尝试指定编码在JSP页面标题,就像这样:

<%@ page session="false" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" trimDirectiveWhitespaces="true" %> 
0

由于您使用response.setCharacterEncoding(),为什么不设置Content-Type的不指定字符集设置字符编码?

response.setContentType("application/json");