/java/

Spring Boot. robots.txt

2016-01-16 02:24:23

../src/main/resources/robot.txt

User-agent: *
Disallow: /cart/

MainController.java

@RequestMapping(value = {"/robots", "/robot", "/robot.txt", "/robots.txt", "/null"})
public void robot(HttpServletResponse response) {

    InputStream resourceAsStream = null;
    try {

        ClassLoader classLoader = getClass().getClassLoader();
        resourceAsStream = classLoader.getResourceAsStream("robot.txt");

        response.addHeader("Content-disposition", "filename=robot.txt");
        response.setContentType("text/plain");
        IOUtils.copy(resourceAsStream, response.getOutputStream());
        response.flushBuffer();
    } catch (Exception e) {
        LOGGER.error("Problem with displaying robot.txt", e);
    } finally {
        InputStreamUtil.close(resourceAsStream);
    }
}