Spring 从 root 上设置的 urlrewrite 规则中排除页面

发布于 2024-09-11 03:24:33 字数 2006 浏览 7 评论 0原文

这是问题的简单解释:

我有一个控制器 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

温折酒 2024-09-18 03:24:33

在你的 urlrewrite.xml 中你会有类似的东西

<rule>
     <from>^/location/([A-Z]+)/name/([A-Z]+)</from>
     <to>/login?name=$2&location=$1</to>
</rule>

In your urlrewrite.xml you'd have something like

<rule>
     <from>^/location/([A-Z]+)/name/([A-Z]+)</from>
     <to>/login?name=$2&location=$1</to>
</rule>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文