【问题标题】:Restrict specific page in grails webapplication限制 grails webapplication 中的特定页面
【发布时间】:2013-11-29 13:36:10
【问题描述】:

我在 grails 中有一个小网站,它有两个页面。第一个是开始页面,第二个页面是详细信息页面。此页面的 URL 是 http://somecomp.com/starthttp://somecomp.com/details

现在我的第一个页面是起始页面,有一个标签可以将最终用户带到详细信息页面。

我想基本上确保我的所有最终用户首先进入起始页面,然后导航到详细信息页面。如果他直接打开http://somecomp.com/details,我想限制用户。

这可以在 grails 和 grrovy 中以某种快速的方式完成吗?任何指针都会有所帮助。

谢谢JK

【问题讨论】:

    标签: grails grails-2.0 grails-controller


    【解决方案1】:

    一种简单的方法是使用过滤器在details 页面之前拦截您的请求,然后检查会话中可能存在的某种标志,以查看是否首先访问了起始页面。

    在您的索引或起始页的第一个操作中设置该标志。

    启动控制器

    def index(){
       session.startVisited = new Date()
    } 
    

    .

    class StartPageFilters {
        def filters = {
            startCheck(controller: '*', action: '*') {
                before = {
                    if (!session.startVisited ) {
                        redirect(action: '....')
                        return false
                    }
                }
            }
        }
    }
    

    【讨论】:

      【解决方案2】:

      对于所需的场景,实现目标的真正方法是使用 Grails Webflow plugin link。对于工作示例,您可以参考this git repository

      【讨论】:

      • 这么小的钉子用大锤子。
      猜你喜欢
      • 1970-01-01
      • 2018-07-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-02
      • 1970-01-01
      相关资源
      最近更新 更多