【问题标题】:How to get struts2 action messages on to Modal如何将 struts2 动作消息发送到 Modal
【发布时间】:2014-12-27 09:34:30
【问题描述】:

我有一个登录模式。 modal(bootstrap) 表单是 header.jsp 的一部分,它包含在每个 JSP 中。 如果用户输入错误的用户名/密码,如何将操作错误消息返回到我的模式?

Struts.xml

<action name="authenticate" method="login"
       class="app.resumerepo.in.action.LoginAction">
    <interceptor-ref name="loginCheck" />
    <result name="success" type="redirect">myaccount.action</result>
    <result name="input"> </result>
    <result name="error">/jsp/common/error.jsp</result>
</action>

对于结果“输入”我应该提到什么,以便我在登录模式上收到操作错误消息?

【问题讨论】:

    标签: twitter-bootstrap jsp struts2 struts2-jquery struts-action


    【解决方案1】:

    我将更正拦截器部分和 在登录失败时,我重定向到一个 login_error.jsp,在那里我调用了相同的模式。 它按预期工作。

                        <%@page session="false"%>
                        <%@taglib uri="/struts-tags" prefix="s"%>
                        <%@ taglib uri="http://displaytag.sf.net" prefix="display"%>
                        <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
                        <html>
                        <head>
                        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
                        <title>Insert title here</title>
    
                        </head>
                        <body style="background-color:#FFF;">
                           <script type="text/javascript">
                            $('#myModal').modal('show'); 
                           </script>
    
                        </body>
                        </html> 
    

    【讨论】:

      【解决方案2】:
      1. 确保您的 loginCheck 是一个拦截器堆栈,而不是单个拦截器。在后一种情况下,创建一个自定义拦截器堆栈,其中包含您的 loginCheck 拦截器,或者像这样声明您的拦截器和 defaultStack

        <action name="authenticate" method="login"
               class="app.resumerepo.in.action.LoginAction">
            <interceptor-ref name="loginCheck"   />
            <interceptor-ref name="defaultStack" />
            ...
        
      2. 在您的代码中,没有显示您是如何登陆登录页面的;顺便说一句,要使其按您的要求工作,只需配置 input 结果以返回您来自的 JSP 页面,例如:

        <result name="input">login.jsp</result>
        

        看看this example 可能会有所帮助。

      【讨论】:

      • 是的,在重定向的 JSP 上我只是调用了相同的登录模式。它现在可以工作了!!
      • 很好,很高兴有帮助。任何不投票的理由(我看到你投了 0 票,永远!..)
      • 我需要多一份帮助.. 在这里stackoverflow.com/questions/26621994/…
      猜你喜欢
      • 1970-01-01
      • 2023-04-02
      • 1970-01-01
      • 2015-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多