简体   繁体   中英

Why the JSP Page encoding directive should be the first line in JSP?

I mean the following directive

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

I have lots of JSPs. I wrote this line in a common file that was already included in all JSPs. But that didn't help, I could see browser using different encoding than what I specified in above directive.

I had to manually wrote that directive as the first line to solve the problem.

I am asking this question in context of problem raised in this article

问题是,在该指令之前的任何内容都将其输出写入到浏览器的输出流中 - 并且编码指定该流如何将页面的String内容转换为字节,因此必须在在写入任何内容之前创建流。

Java运行时如何知道该文件是一个JSP,从而编译和处理它,而不是像纯文本一样推送到客户端?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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