Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java (JSP): repeating the contentType header in a "sub-jsp"

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

For example if example.jsp starts with this:

<?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"/>
...

(it includes support.jsp)

And then support.jsp starts also with this:

<?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?

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

like image 835
SyntaxT3rr0r Avatar asked May 24 '10 17:05

SyntaxT3rr0r


1 Answers

From JSP Specification:

JSP.5.4 <jsp:include>

...

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.

like image 179
axtavt Avatar answered Oct 21 '22 18:10

axtavt