Java(JSP):在"sub-jsp"中重复contentType标头. [英] Java (JSP): repeating the contentType header in a "sub-jsp"

查看:78
本文介绍了Java(JSP):在"sub-jsp"中重复contentType标头.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在包含在另一个.jsp中的.jsp中重复标题时会发生什么?

What happens when headers are repeated in a .jsp you include in another .jsp?

例如,如果 example.jsp 以此开头:

<?xml version="1.0" encoding="UTF-8"?>
<jsp:root version="2.0" xmlns:jsp="http://java.sun.com/JSP/Page">
<jsp:directive.page contentType="text/html; charset=UTF-8" />

<div class="content">

<jsp:include page="support.jsp"/>
...

(包括 support.jsp )

然后 support.jsp 以此开始:

<?xml version="1.0" encoding="UTF-8"?>
<jsp:root version="2.0" xmlns:jsp="http://java.sun.com/JSP/Page">
<jsp:directive.page contentType="text/html; charset=UTF-8" />
... 

有问题吗?这是不好的做法吗?

Is that a problem? Is it bad practice?

重复几次标头仅与结果.html页面中的一个标头相对应的时候,具体会发生什么?

What does concretely happen when you repeat several times a header that only corresponds to one header in the resulting .html page?

推荐答案

来自 JSP规格:

JSP.5.4< jsp:include>

JSP.5.4 <jsp:include>

...

包含的页面无法更改 响应状态代码或设置标头. 这排除了调用诸如 setCookie.尝试调用这些 方法将被忽略.这 约束相当于一个 施加于 RequestDispatcher类.

An included page cannot change the response status code or set headers. This precludes invoking methods like setCookie. Attempts to invoke these methods will be ignored. The constraint is equivalent to the one imposed on the include method of the RequestDispatcher class.

也就是说,设置内容类型的尝试将被忽略.

That is, attempt to set content type will be ignored.

这篇关于Java(JSP):在"sub-jsp"中重复contentType标头.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆