1. <small id='AyIAG'></small><noframes id='AyIAG'>

    <i id='AyIAG'><tr id='AyIAG'><dt id='AyIAG'><q id='AyIAG'><span id='AyIAG'><b id='AyIAG'><form id='AyIAG'><ins id='AyIAG'></ins><ul id='AyIAG'></ul><sub id='AyIAG'></sub></form><legend id='AyIAG'></legend><bdo id='AyIAG'><pre id='AyIAG'><center id='AyIAG'></center></pre></bdo></b><th id='AyIAG'></th></span></q></dt></tr></i><div id='AyIAG'><tfoot id='AyIAG'></tfoot><dl id='AyIAG'><fieldset id='AyIAG'></fieldset></dl></div>
      <bdo id='AyIAG'></bdo><ul id='AyIAG'></ul>

  2. <legend id='AyIAG'><style id='AyIAG'><dir id='AyIAG'><q id='AyIAG'></q></dir></style></legend>
  3. <tfoot id='AyIAG'></tfoot>

      拦截器无法访问操作参数

      Interceptor can#39;t access Action Parameters(拦截器无法访问操作参数)

    1. <small id='L5UXf'></small><noframes id='L5UXf'>

      • <bdo id='L5UXf'></bdo><ul id='L5UXf'></ul>

          1. <i id='L5UXf'><tr id='L5UXf'><dt id='L5UXf'><q id='L5UXf'><span id='L5UXf'><b id='L5UXf'><form id='L5UXf'><ins id='L5UXf'></ins><ul id='L5UXf'></ul><sub id='L5UXf'></sub></form><legend id='L5UXf'></legend><bdo id='L5UXf'><pre id='L5UXf'><center id='L5UXf'></center></pre></bdo></b><th id='L5UXf'></th></span></q></dt></tr></i><div id='L5UXf'><tfoot id='L5UXf'></tfoot><dl id='L5UXf'><fieldset id='L5UXf'></fieldset></dl></div>

                <tbody id='L5UXf'></tbody>

              <tfoot id='L5UXf'></tfoot>
              1. <legend id='L5UXf'><style id='L5UXf'><dir id='L5UXf'><q id='L5UXf'></q></dir></style></legend>
                本文介绍了拦截器无法访问操作参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在为 struts2 拦截器创建一个示例.我创建了一个简单的登录页面并使用自定义拦截器类来加密输入.但是拦截器正在将 ValueStack 的输入值读取为 null.

                I'm creating an example for struts2 interceptors. I created a simple login page and used a custom interceptor class to encrypt the input. But the interceptor is reading the values of input from ValueStack as null.

                我不明白我做错了什么.我想 struts.xml 和拦截器类是足够的数据.如果您需要更多我的代码,请告诉.

                I don't understand what am I doing wrong. I suppose struts.xml and interceptor class are enough data for this. If you need some more of my code, please tell.

                struts.xml

                <?xml version="1.0" encoding="UTF-8"?>
                <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd">
                <struts>
                    <constant name="struts.devMode" value="true" />
                    <package name="myPackage" extends="struts-default">
                    <interceptors>
                            <interceptor name="encrypt" class="com.keyur.struts2.interceptors.EncryptDecryptInterceptor"/>
                        </interceptors>
                        <action name="validatorAction" class="com.keyur.struts2.ActionClasses.validatorClass" method="execute">
                        <interceptor-ref name="encrypt"></interceptor-ref>
                        <result name="success">/success.jsp</result>
                        <result name="input">/index.jsp</result>
                        </action>
                    </package>
                </struts>
                

                拦截器 .java 文件

                package com.keyur.struts2.interceptors;
                
                import com.keyur.struts2.ActionClasses.validatorClass;
                import com.keyur.struts2.beans.EncryptorDecryptor;
                import com.opensymphony.xwork2.ActionInvocation;
                import com.opensymphony.xwork2.interceptor.Interceptor;
                import com.opensymphony.xwork2.util.ValueStack;
                
                public class EncryptDecryptInterceptor implements Interceptor {
                
                        EncryptorDecryptor encdec = new EncryptorDecryptor();
                
                    @Override
                    public void destroy() {
                        // TODO Auto-generated method stub
                
                    }
                
                    @Override
                    public void init() {
                        // TODO Auto-generated method stub
                
                    }
                
                    @Override
                    public String intercept(ActionInvocation arg0) throws Exception {
                        // TODO Auto-generated method stub
                
                        String result = arg0.invoke();
                
                        ValueStack stack = arg0.getStack();
                        String username = stack.findString("username");
                        String password = stack.findString("password");
                
                        System.out.println("Username: "+((validatorClass)stack.peek()).getUsername());
                        System.out.println("Password: "+((validatorClass)stack.peek()).getPassword());
                        //System.out.println(username);
                        //System.out.println(password);
                
                        //stack.set("username", encdec.encryptText(username));
                        //stack.set("password", encdec.encryptText(password));
                
                        return result;
                    }
                }
                

                EncryptorDecryptor 是我定义的一个单独的类,它自己可以正常工作.

                EncryptorDecryptor is the a separate class which I have defined and it is working correctly on it's own.

                推荐答案

                如果要访问参数,params 拦截器应该先去

                If you want to access parameters, the params interceptor should go first

                <action name="validatorAction" class="com.keyur.struts2.ActionClasses.validatorClass" method="execute">
                   <interceptor-ref name="params"></interceptor-ref>
                   <interceptor-ref name="encrypt"></interceptor-ref>
                   <interceptor-ref name="defaultStack"></interceptor-ref>
                   <result name="success">/success.jsp</result>
                   <result name="input">/index.jsp</result>
                </action>
                

                您的问题是这些参数没有进入 valueStack,您可能应该从操作上下文中获取它们.

                Your problem is that those parameters don't go to the valueStack, and you should probably get them from the action context.

                Map params = ActionContext.getContext().getParameters();
                

                但是在 params 拦截器之后它们应该在那里.

                But after params interceptor they should be there.

                这篇关于拦截器无法访问操作参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Java Bytecode Manipulation Library Suggestions(Java 字节码操作库建议)
                Java CLI UI-design: frameworks or libraries?(Java CLI UI 设计:框架还是库?)
                About the use of Beans.xml configuration file in Spring Framework application(关于Spring Framework应用中Beans.xml配置文件的使用)
                What is the difference between Spring, Struts, Hibernate, JavaServer Faces, Tapestry?(Spring、Struts、Hibernate、JavaServer Faces、Tapestry 有什么区别?)
                Are there any android application framework like spring?(有没有像spring这样的android应用程序框架?)
                Java Swing based game framework. Any advice?(基于 Java Swing 的游戏框架.有什么建议吗?)
                  <tbody id='fZS57'></tbody>

                <i id='fZS57'><tr id='fZS57'><dt id='fZS57'><q id='fZS57'><span id='fZS57'><b id='fZS57'><form id='fZS57'><ins id='fZS57'></ins><ul id='fZS57'></ul><sub id='fZS57'></sub></form><legend id='fZS57'></legend><bdo id='fZS57'><pre id='fZS57'><center id='fZS57'></center></pre></bdo></b><th id='fZS57'></th></span></q></dt></tr></i><div id='fZS57'><tfoot id='fZS57'></tfoot><dl id='fZS57'><fieldset id='fZS57'></fieldset></dl></div>

                <small id='fZS57'></small><noframes id='fZS57'>

                    <bdo id='fZS57'></bdo><ul id='fZS57'></ul>
                      • <legend id='fZS57'><style id='fZS57'><dir id='fZS57'><q id='fZS57'></q></dir></style></legend>

                        1. <tfoot id='fZS57'></tfoot>