开发者

Spring MVC 3 redirect / forward with 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 vali开发者_C百科date 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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜