Reputation: 3744
In JavaEE application.
I have index.html page as "welcome-file" in web.xml
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
I want to add Http Header into response for index.html
One way is use index.jsp instead of index.html and add inside an scriptlet:
<% response.addHeader("X-Frame-Options", "DENY"); %>
Is there any other way?
Is there an possiblility to add some kind of filter
For example something like:
WelcomeFileFilter {
void filter(HttpServletResponse response) {
response.addHeader("X-Frame-Options", "DENY");
}
}
Because I don't want to use index.jsp instead of index.html.
Upvotes: 3
Views: 18683
Reputation: 10533
You can ask your web server/servlet container to add those headers for you. It will be configured in the server configuration files not in web.xml.
Or you can create a filter that will add headers for you. You'll have to configure the filter in your web.xml.
This stackoverflow answer show you how to configure jetty to add headers. This other stackoverflow answer shows you how to code a Filter that add headers.
Upvotes: 1