简体   繁体   中英

How to Add robots.txt to a Vaadin 7 Application with CDI-Integration?

how can I add a robots.txt file to a Vaadin application?

I found nearly nothing related, but what I found states that there is no support for such a file.

I'm using Vaadin 7.1.1 with JBoss 7.1.1 and Vaadin-CDI-Integration.


My workaround approach is: By adding RobotsUI to the project, the URL http://localhost:8080/App/robots.txt becomes accessible.

@CDIUI(value="robots.txt")
public class RobotsUI extends UI {

    @Override
    protected void init(VaadinRequest request) {
        // Send a response with mimetype 
        // `text/plain` with self defined content.
    }

}

My problem is: How can I deliver a self-edited, text/plain response?

Thanks for any help :-)

I successfully published text/plain by adding a common HttpServlet to the project:

@WebServlet("/robots.txt")
public class RobotsServlet extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.getWriter().write("Text...\n");
    }

}

Do it outside of Vaadin, register a filter before vaadin servlet and in case of robots.txt uri return your robots file. Or add some static resource serving servlet registered lets say to /static/* and bind your /robots.txt redirect with UrlRewrite .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM