Spring MVC 3 使用 sitemesh 重定向/转发

发布于 2024-10-21 19:30:04 字数 1519 浏览 0 评论 0原文

大家好,

我正在使用 spring mvc 3 + sitemesh 和 spring security 3。我需要执行以下场景。 我为绕过用户和普通用户使用两种不同的布局。我遵循的方法工作正常,直到我遇到一些 JavaScript 弹出窗口,因为我注意到页面加载了两次并弹出了同一个窗口两次。请验证我的方法。

控制器类-

    @RequestMapping(value = "/mainMenu")
    public class PortalController {

     @RequestMapping(method = RequestMethod.GET)
    public String byPassPortal() {

    if (User.bypassMenu()) {
         //return "redirect:user.html";
         //return "forward:user.html";
         return "/user/user";
    } else {
        // send user to the portal page
        logger.debug("Redirect to the main page");
        return "mainMenu";
    }
    }
}

站点网格装饰器 xml -

<decorators defaultdir="/decorators">
<decorator name="layout" page="layout.jsp">
    <pattern>/user*</pattern>
</decorator>
<decorator name="default" page="default.jsp">
    <pattern>/*</pattern>
</decorator>
</decorators>

这是我的观察结果 - 如果我使用 return "redirect:user.html"; & return "forward:user.html"; 对于用户来说,它可以很好地使用正确的布局 (layout.jsp),因为装饰器将通过模式 捕获它。模式>/用户*。但问题是表单将加载两次,并且弹出窗口两次。

如果我使用 return "forward:user.html";return "/user/user"; 弹出窗口只会出现一次,但布局是错误的。原因应该是这样它不会从 url 模式 /user* 的装饰器中捕获,并且它将使用错误的默认布局(default.jsp )。

我认为有一些事情需要从 spring 侧处理,而不是从 sitemesh 处理。您能在这方面给予一些指导吗?先感谢您。

Greetings all,

I am using spring mvc 3 + sitemesh and spring security 3. i need to do the following scenario.
i am using 2 different layouts for the bypassing users and normal users. the approach i followed was working fine until i came across with some JavaScript popups because i noticed that the page was loading twice and poping up the same window twice. please validate my approach.

Controller class-

    @RequestMapping(value = "/mainMenu")
    public class PortalController {

     @RequestMapping(method = RequestMethod.GET)
    public String byPassPortal() {

    if (User.bypassMenu()) {
         //return "redirect:user.html";
         //return "forward:user.html";
         return "/user/user";
    } else {
        // send user to the portal page
        logger.debug("Redirect to the main page");
        return "mainMenu";
    }
    }
}

site mesh decorator xml -

<decorators defaultdir="/decorators">
<decorator name="layout" page="layout.jsp">
    <pattern>/user*</pattern>
</decorator>
<decorator name="default" page="default.jsp">
    <pattern>/*</pattern>
</decorator>
</decorators>

here are my observations - if i use return "redirect:user.html"; & return "forward:user.html"; it was working fine with the correct layout (layout.jsp) for users since decorator will catch it by pattern <pattern>/user*</pattern>. but the problem is form will load twice and i get the popup twice.

if i use return "forward:user.html"; or return "/user/user"; popup will come only once but the layout is wrong.cause should be that it will not captured from the decorator for url pattern <pattern>/user*</pattern> and it will use the default layout which is wrong (default.jsp).

I think there is something to handle from the spring side and not from the sitemesh. can you please give some guidance among this? Thank you in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

冰之心 2024-10-28 19:30:04

我发现了这个问题。与 spring 或 sitemesh 无关。这完全是关于我使用的第二种布局。它包含两个 '' 标签,并且由 sitemesh 提交了两次。希望这对任何遇到此类错误的人有所帮助。 – Sam 0 秒前编辑

i found the issue.there was nothing to do with spring or sitemesh. it was all about the second layout that i was using. it contained two '' tags and it submitted twice by the sitemesh. Hope this will help for anyone who got this kind of error down the line. – Sam 0 secs ago edit

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文