Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Htaccess是否更改页面的内容类型?_Java_.htaccess_Utf 8_Response_Content Type - Fatal编程技术网

Java Htaccess是否更改页面的内容类型?

Java Htaccess是否更改页面的内容类型?,java,.htaccess,utf-8,response,content-type,Java,.htaccess,Utf 8,Response,Content Type,我的Java端有这样的代码: .... PrintWriter writer = response.getWriter(); response.setContentType("application/json; charset=utf-8"); response.setCharacterEncoding("UTF-8"); .... 我在MySQL和Apache上使用Struts2、JSP和Java实现我的应用程序。当我向响应对象写入内容并在firebug上检查内容类型时,它总是 charse

我的Java端有这样的代码:

....
PrintWriter writer = response.getWriter();
response.setContentType("application/json; charset=utf-8");
response.setCharacterEncoding("UTF-8");
....
我在MySQL和Apache上使用Struts2、JSP和Java实现我的应用程序。当我向响应对象写入内容并在firebug上检查内容类型时,它总是

charset=ISO-8859-1
所以,当我想在响应对象上写东西时,会出现无法识别的字符

每次我的jsp文件第一次都有这一行:

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

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

我试过这样的方法:


但是,我不确定我是否错过了什么或尝试了其他方法?

尝试在JSP页面标题中指定编码,如下所示:

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

既然您正在使用
response.setCharacterEncoding()
设置字符编码,为什么不直接设置内容类型而不指定字符集呢

response.setContentType("application/json");