Java 有没有办法用tomcat实现X-Robots-Tag指令?
我想将Java 有没有办法用tomcat实现X-Robots-Tag指令?,java,spring-boot,tomcat,heroku,x-robots-tag,Java,Spring Boot,Tomcat,Heroku,X Robots Tag,我想将X-Robots-Tag noindex,nofollow添加到站点所有.PDF文件的HTTP响应中,以避免这些文档被谷歌搜索引擎引用 这是针对Heroku上的Tomcat8服务器的SpringBoot2.1版本。从过去开始,我在Apache服务器上进行了尝试,noindex和nofollow运行良好 <Files ~ "\.pdf$"> Header set X-Robots-Tag "noindex, nofollow" </Files> 标题集X-Ro
X-Robots-Tag noindex,nofollow
添加到站点所有.PDF文件的HTTP响应中,以避免这些文档被谷歌搜索引擎引用
这是针对Heroku上的Tomcat8服务器的SpringBoot2.1版本。从过去开始,我在Apache服务器上进行了尝试,noindex
和nofollow
运行良好
<Files ~ "\.pdf$">
Header set X-Robots-Tag "noindex, nofollow"
</Files>
标题集X-Robots-Tag“noindex,nofollow”
您可以创建一个servlet过滤器,根据需要执行此操作
@WebFilter(urlPatterns = {"*.pdf"})
public class PdfFilter implements Filter {
@Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
HttpServletResponse httpServletResponse = (HttpServletResponse)response;
httpServletResponse.addHeader("X-Robots-Tag", ""noindex, nofollow");
chain.doFilter(request, response);
}
}