htaccess改变页面的内容类型?
我的 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 改变了内容类型。
我尝试了类似这里的操作:
http://www.askapache.com/htaccess /setting-charset-in-htaccess.html
但是我不确定我是否错过了什么或尝试了其他什么?
I have that code at my Java side:
....
PrintWriter writer = response.getWriter();
response.setContentType("application/json; charset=utf-8");
response.setCharacterEncoding("UTF-8");
....
I use Struts2, JSP and Java for my application over MySQL and Apache. When I write something to response object and check the content type at firebug it is always
charset=ISO-8859-1
So, when I want to writing something over response object there occurs unrecognized characters.
My jsp files has that line at first every time:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
I tested my program and when it works without passing over .htaccess everything is OK. I know that .htaccess changes the content type.
I tried something like here:
http://www.askapache.com/htaccess/setting-charset-in-htaccess.html
However I am not sure do I miss something or try anything else?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试在 JSP 页面标头中指定编码,如下所示:
Try to specify the encoding in your JSP page header, like this:
既然您使用
response.setCharacterEncoding()
设置字符编码,为什么不直接设置 Content-Type 而不指定字符集呢?Since you're setting your character encoding using
response.setCharacterEncoding()
, why not just set the Content-Type without specifying charset?