Spring 从 root 上设置的 urlrewrite 规则中排除页面
这是问题的简单解释:
我有一个控制器 RedirectController,以便我想处理 http://mydomain/**
但是,我仍然需要将 http://mydomain/ 重定向到索引控制器(或 index.jspx 等)将来我很可能需要排除 /help /about URL。
目前的方法是我没有改变Spring Roo生成的urlrewrite.xml。这里是。 代码:
<urlrewrite default-match-type="wildcard">
<rule>
<from>/resources/**</from>
<to last="true">/resources/$1</to>
</rule>
<rule>
<from>/static/WEB-INF/**</from>
<set type="status">403</set>
<to last="true">/static/WEB-INF/$1</to>
</rule>
<rule>
<from>/static/**</from>
<to last="true">/$1</to>
</rule>
<rule>
<from>/</from>
<to last="true">/app/index</to>
</rule>
<rule>
<from>/app/**</from>
<to last="true">/app/$1</to>
</rule>
<rule>
<from>/**</from>
<to>/app/$1</to>
</rule>
<outbound-rule>
<from>/app/**</from>
<to>/$1</to>
</outbound-rule>
</urlrewrite>
然后我在 RedirectController 中使用了映射注释。
@RequestMapping("/**")
@Controller
public class RedirectController {
....
@RequestMapping(method = RequestMethod.GET, value = "/{value}")
public String get(@PathVariable String value, ModelMap modelMap, HttpServletRequest request, HttpServletResponse response) {
...
这样当http://mydomain/xxx被请求时,这个get()方法就会使用xxx值。但是,当我使用这样的方案时,在 http://mydomain/ 请求中,索引作为 {value} 传递(例如如 xxx)。 (这是我不想要的。)
根据上面 xml 文件中的映射规则,任何 /** 请求都会重定向到 web.xml 文件中的 DispatcherServlet,以便基于注释的映射处理程序查看 RedirectController 的注释并简单地包含我们想要排除的所有 URL...
有解决此问题的想法吗?
Here is the simple explanation of the problem:
I have a controller RedirectController so that I want to handle everything like http://mydomain/**
However, still I want need to redirect http://mydomain/ to index controller (or index.jspx whatever) and most probably I need to exclude /help /about URLs in the future.
The current method is I did not changed Spring Roo generated urlrewrite.xml. Here it is.
Code:
<urlrewrite default-match-type="wildcard">
<rule>
<from>/resources/**</from>
<to last="true">/resources/$1</to>
</rule>
<rule>
<from>/static/WEB-INF/**</from>
<set type="status">403</set>
<to last="true">/static/WEB-INF/$1</to>
</rule>
<rule>
<from>/static/**</from>
<to last="true">/$1</to>
</rule>
<rule>
<from>/</from>
<to last="true">/app/index</to>
</rule>
<rule>
<from>/app/**</from>
<to last="true">/app/$1</to>
</rule>
<rule>
<from>/**</from>
<to>/app/$1</to>
</rule>
<outbound-rule>
<from>/app/**</from>
<to>/$1</to>
</outbound-rule>
</urlrewrite>
Then I used mapping annotations in my RedirectControlller.
@RequestMapping("/**")
@Controller
public class RedirectController {
....
@RequestMapping(method = RequestMethod.GET, value = "/{value}")
public String get(@PathVariable String value, ModelMap modelMap, HttpServletRequest request, HttpServletResponse response) {
...
So that when http://mydomain/xxx is requested, this get ( ) method will use xxx value. However, when I use such a scheme, on http://mydomain/ request, index is passed as {value} (such as xxx). (which is something I do not want.)
According to mapping rules in the xml file above, any /** request is redirected to DispatcherServlet in the web.xml file so that annotation based mapping handler look at the annotation of RedirectController and simply includes all the URLs we want to exclude...
Any ideas to solve this issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在你的 urlrewrite.xml 中你会有类似的东西
In your urlrewrite.xml you'd have something like