【问题标题】:How to Add robots.txt to a Vaadin 7 Application with CDI-Integration?如何使用 CDI 集成将 robots.txt 添加到 Vaadin 7 应用程序?
【发布时间】:2013-08-02 16:35:42
【问题描述】:

如何将 robots.txt 文件添加到 Vaadin 应用程序?

我几乎没有发现任何相关内容,但我发现不支持此类文件。

我将 Vaadin 7.1.1 与 JBoss 7.1.1 和 Vaadin-CDI-Integration 一起使用。


我的解决方法是:通过将 RobotsUI 添加到项目中,可以访问 URL http://localhost:8080/App/robots.txt

@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.
    }

}

我的问题是:我如何提供自编辑的text/plain 回复?

感谢您的帮助:-)

【问题讨论】:

    标签: java jboss7.x vaadin cdi robots.txt


    【解决方案1】:

    我通过在项目中添加通用HttpServlet 成功发布了text/plain

    @WebServlet("/robots.txt")
    public class RobotsServlet extends HttpServlet {
    
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            response.getWriter().write("Text...\n");
        }
    
    }
    

    【讨论】:

      【解决方案2】:

      在 Vaadin 之外进行,在 vaadin servlet 之前注册一个过滤器,如果是 robots.txt uri,则返回您的机器人文件。或者添加一些静态资源服务 servlet 注册让我们说 /static/* 并将 /robots.txt 重定向与 UrlRewrite 绑定。

      【讨论】:

      • 在 Vaadin 之外解决问题的好主意。因此,我基于我的答案,此外还避免了 JAR 包。谢谢!
      猜你喜欢
      • 1970-01-01
      • 2016-08-20
      • 2012-07-02
      • 2013-07-29
      • 2019-08-02
      • 1970-01-01
      • 2013-05-20
      • 2011-03-30
      相关资源
      最近更新 更多