简体   繁体   English

将字符集添加到响应头

[英]Adding charset to the response header

I am using following to run my web application - 我正在使用以下程序来运行我的Web应用程序-

  1. Eclipse 日食
  2. Java 1.6_21 Java 1.6_21
  3. Tomcat Tomcat的

When i run my application on my local machine using eclipse, in the response header i can see that Content-Type is set to following - 当我使用eclipse在本地计算机上运行应用程序时,在响应标头中,我可以看到Content-Type设置为以下内容-

Content-Type:text/html;charset=ISO-8859-1 内容类型:text / html的;字符集= ISO-8859-1

But when i run my application on the production servers by deploying war file in the tomcat then the Content-Type in the response header is set to following - 但是,当我通过在tomcat中部署war文件在生产服务器上运行我的应用程序时,响应标头中的Content-Type设置为-

Content-Type:text/html 内容类型:text / html的

I want to know how charset=ISO-8859-1 is set when i run application on my local machine and why it is not getting set on the production environment. 我想知道在本地计算机上运行应用程序时如何设置charset = ISO-8859-1以及为什么在生产环境中未设置它。

Do I need to do something in the tomcat configuration on the production environment to ensure that chartset is set into the Content-Type or the problem lies somewhere else? 我是否需要在生产环境的tomcat配置中执行某些操作,以确保将图表集设置为Content-Type或问题出在其他地方?

For servlets, you can just set it in the response, eg: 对于servlet,您可以在响应中进行设置,例如:

response.setContentType("text/html;charset=ISO-8859-1");
response.setCharacterEncoding("ISO-8859-1");

For JSP, you set it in a page directive: 对于JSP,可在页面指令中进行设置:

<%@ page contentType="text/html;charset=ISO-8859-1" %>

For Tomcat global, the answer here may help. 对于Tomcat全局, 这里的答案可能会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM