条纹 URL 前缀作为请求参数
我正在尝试为我的应用程序构建一种方法,使其具有类似于 Twitter 等应用程序的 URL 模式/方案。例如 myapplication.com/username,其中用户名是被视为参数的实际用户名。该参数将用于显示用户相关页面。我的应用程序也有这个 URL 方案,其中用户名是其他资源的前缀,例如 myapplication.com/username/accountsettings 或 myapplication.com/username/profile。用户名充当某种子上下文路径。
正如标题所示,我使用的是 Stripes。我现在要做的是创建一个自定义 ActionResolver,在其中从 URL 绑定中取出第一个非空字符串(在本例中为用户名),因为我的 ActionBeans 不考虑 URL 前面的用户名。例如,处理 myapplication.com/username/accountsettings 的操作 bean 仅绑定到 /accountsettings。
当我尝试使用自定义 ActionResolver 作为 Stripes 过滤器的 ActionResolver.Class 初始化参数时,它似乎不起作用。看起来它仍然使用默认的 ActionResolver。我该如何改变这个?
另外,有没有更简单/更直观的方法来做到这一点?我对 Stripes 和 URL 绑定不是很熟悉,那么 Stripes 中是否有一种工具可以让我在不扩展/更改框架组件的情况下执行此操作?
谢谢。
I'm trying to build a way for my application to have a URL pattern/scheme like that of applications like Twitter. For example myapplication.com/username where the username is an actual username treated as a parameter. This parameter will be used to display the user related page. My application also has this URL scheme where the username is a prefix for other resources e.g. myapplication.com/username/accountsettings or myapplication.com/username/profile. The username acts some sort of sub-context path.
As the title suggests, I'm using Stripes for it. What I'm doing now is create a custom ActionResolver where I take out the first non-empty string from the URL binding (the username in this case) since my ActionBeans do not take into account the username prepended to the URL. So for example, the action bean that handles myapplication.com/username/accountsettings is only bound to /accountsettings.
When I tried to use the custom ActionResolver as ActionResolver.Class init param for the Stripes filter, it doesn't seem to be working. It seems like it's still using the default ActionResolver. How do I alter this?
Also, is there an easier/more intuitive way to do this? I'm not very familiar with Stripes and URL bindings so is there a facility in Stripes that would allow me to do this without extending/altering the framework components?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我同意卢卡斯的观点,URL映射应该由 UrlBinding 完成注解。没有必要开始搞乱 URL 重新映射过滤器,这只会破坏 Stripes 系统为您生成正确的 URL。
它应该是这样的:
I agree with lucas, URL mappings should be done by UrlBinding annotation. There is no need to start messing around with URL remapping filters, that will only break the Stripes system in generating correct URL’s for you.
This is how it should look like:
我偶然发现了 URL 重写过滤器,到目前为止它似乎满足我的应用程序的需求。
I stumbled upon URL Rewrite Filter and it seems to fit the needs of my application so far.
Stripes 确实内置了这个功能。它称为 @URLBinding 注释,它包含在 Stripes 1.5 中。 这里有一些文档,并且Stripes 书 IIRC 中有更多内容。
Stripes does have this built in. It's called the @URLBinding annotation, and it was included in Stripes 1.5. There is some documentation here, and there was more in the Stripes book IIRC.