1

我必须像这样过滤网址:

http://www.mysite.com/708e93

哪里708e93是唯一的 id,基于这个 id 我必须在 jsp 中创建动态页面。

现在的问题是 - 我在过滤器映射下的 url-pattern 中放了什么

<filter-mapping>
<filter-name>foo.bar.MyFilter</filter-name>
<url-pattern> ?? </url-pattern>
</filter-mapping>

如果我将 root (/) 放在 url-pattern 中..对 mysite 的每个请求都将被过滤,那么在这种情况下我怎样才能获得唯一的 id?

有什么解决办法吗?

编辑

我不想像这样在 url 中添加目录:http://www.mysite.com/dynamicpages/708e93

4

1 回答 1

1

For dynamic url's such as use case you have. you should be have all the dynamic pages inside a directory, lets say dynamicpages folder. And you should be mapping a directory url pattern like below :

<filter-mapping>
  <filter-name>foo.bar.MyFilter</filter-name>  
  <url-pattern>/dynmaicpages/*</url-pattern>
</filter-mapping>

<servlet-mapping>
  <servlet-name>foo.bar.MyServlet</servlet-name>  
  <url-pattern>/dynmaicpages/*</url-pattern>
</servlet-mapping>

You can get the Unique id using the following methods:

  • HttpServletRequest.getPathInfo() If you have servlet mapping like above, this will give you the unique id value directly.

For ex, if the request uri is /dynamicpages/708e93 it will return 708e93.

  • HttpServletRequest.getRequestURI() This will give you the entire request url. And you need to parse the unique id properly.

For ex, if the request uri is /dynamicpages/708e93 it will return /dynamicpages/708e93.

于 2012-07-09T10:36:29.287 回答