Servlet-Filter不受欢迎文件的限制 [英] Servlet-Filter is not honoured for welcome file

查看:125
本文介绍了Servlet-Filter不受欢迎文件的限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用过滤器会动态生成内容,以供网络爬虫显示( https ://developers.google.com/webmasters/ajax-crawling/docs/specification )。如果传入的网址包含路径,此过滤器工作正常( http://www.unclestock .COM / app.jsp#!S = GOOG )。如果传入的网址只包含我的网域(和片段),请说 http://www.unclestock.com #!s = GOOG ,则会返回欢迎文件(app.jsp),但过滤器未被授权。

I am using a Filter do generate dynamicly content to be visible for webcrawlers (https://developers.google.com/webmasters/ajax-crawling/docs/specification). This filter is working fine if the incoming url contains a path (http://www.unclestock.com/app.jsp#!s=GOOG). If the incoming url contains just my domain (and a fragment), say http://www.unclestock.com#!s=GOOG, the welcome file (app.jsp) is returned, but the filter is not honnoured.

我的web.xml包含以下内容过滤器映射:

My web.xml contains the following filter map:

<filter-mapping>
 <filter-name>crawler</filter-name>
 <url-pattern>/app.jsp</url-pattern>
</filter-mapping>

<welcome-file-list>
 <welcome-file>app.jsp</welcome-file>
</welcome-file-list>

我尝试使用index.html欢迎文件,而将其重定向到app.jsp。然后执行过滤器。然而,这并没有解决我的问题:客户端重定向没有跟踪(这是想法),并与服务器端重定向,我会失去我的url片段(我也需要)。

I have tried to use an index.html welcome file instead, which redirects to app.jsp. The filter is then executed. However, this does not solve my problem: A client side redirect is not followed by the crawlers (which is the idea), and with server side redirect, I would loose my url fragment (which I also need).

您是否看到其他解决方案?

Do you see any alternative solution?

我使用的是Google Appengine。

I'm using Google Appengine.

推荐答案

我通过使用一个欢迎的servlet来完成RequestDispatcher的转发。请注意,必须将调度程序FORWARD添加到过滤器映射中,以便在过滤期间使过滤器工作。

I solved it by using a welcome servlet which does a RequestDispatcher forward. Note that the dispatcher FORWARD must be added to the filter-mapping in order to have the filter working during the foward.

web.xml:
<filter-mapping>
  <filter-name>crawler</filter-name>
  <url-pattern>*.jsp</url-pattern>
  <dispatcher>REQUEST</dispatcher> 
  <dispatcher>FORWARD</dispatcher>
</filter-mapping>

<welcome-file-list>
  <welcome-file>welcome</welcome-file>
</welcome-file-list>

<servlet>
  <servlet-name>welcome</servlet-name>
  <servlet-class>Welcome</servlet-class>
</servlet>
<servlet-mapping>
  <servlet-name>welcome</servlet-name>
  <url-pattern>/welcome</url-pattern>
</servlet-mapping>

Welcome.java:
public class Welcome extends RemoteServiceServlet {
  public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    RequestDispatcher rd = req.getRequestDispatcher("app.jsp");
    rd.forward(req, resp);
  }
}

这篇关于Servlet-Filter不受欢迎文件的限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆