title: Why my custom interceptor is not working?
body: <p>I have created a custom interceptor <code>MyInterceptor.java</code> in Struts 2, which take the parameters value <code>username</code> and <code>password</code> from <code>index.jsp</code> page and convert the <code>String</code> in these parameters to uppercase.</p>
  <p>Below is my interceptor code in which I am getting <code>java.lang.NullPointerException</code> on Line no. 14</p>
  <p><strong>MyInterceptor.java:</strong></p>
  <pre class="lang-java prettyprint-override"><code>package com.interceptor;
  
  import com.opensymphony.xwork2.interceptor.Interceptor;
  import com.opensymphony.xwork2.util.ValueStack;
  import com.opensymphony.xwork2.ActionInvocation;
  
  public class MyInterceptor implements Interceptor{
      public void init(){}
      @Override
      public String intercept(ActionInvocation ai) throws Exception {
          ValueStack stack = ai.getStack();
          String s1 = stack.findString(&quot;name&quot;);
          String s2 = stack.findString(&quot;password&quot;);
      String s3 = s1.toUpperCase();
       String s4 = s2.toUpperCase();
          stack.set(&quot;name&quot;, s3);
          
          stack.set(&quot;password&quot;, s4);
          return ai.invoke();
      }
      
      @Override
      public void destroy() {
          
      }
  }
  </code></pre>
  <p><strong>Here is my <code>index.jsp</code> page:</strong></p>
  <p>which takes <code>username</code> and <code>password</code> <code>&quot;ravi&quot;</code>:</p>
  <pre class="lang-jsp prettyprint-override"><code>&lt;%@ page language=&quot;java&quot; contentType=&quot;text/html; charset=ISO-8859-1&quot;
      pageEncoding=&quot;ISO-8859-1&quot;%&gt;
  &lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot; &quot;http://www.w3.org/TR/html4/loose.dtd&quot;&gt;
  &lt;%@taglib prefix=&quot;s&quot; uri=&quot;/struts-tags&quot; %&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=ISO-8859-1&quot;&gt;
  &lt;title&gt;Login Page&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;h1&gt;Login Here&lt;/h1&gt;
  &lt;s:form action=&quot;login&quot;&gt;
  
      &lt;s:textfield name=&quot;name&quot; label=&quot;Name&quot;&gt;&lt;/s:textfield&gt;
      &lt;s:textfield type=&quot;password&quot; name=&quot;password&quot; label=&quot;Password&quot;&gt;&lt;/s:textfield&gt;
  &lt;s:submit label=&quot;Login&quot;&gt;&lt;/s:submit&gt;
  &lt;/s:form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p><strong>Here is action class <code>MyAction.java</code></strong>:</p>
  <pre class="lang-java prettyprint-override"><code>package com.ravi.action;
  import com.opensymphony.xwork2.ActionSupport;
  public class MyAction extends ActionSupport{
             public String name;
             public String password;
  
             public void setName(String name){
                                                this.name= name;
                          }
  
             public void setPassword(String password){
                                                      this.password= password;
                         }
  
            public String getName(){
                                      return name;
                         }
  
           public String getPassword(){
                                      return password;
                         }
  
           public String execute()throws Exception{
                      if(name.equals(&quot;RAVI&quot;) &amp;&amp; password.equals(&quot;RAVI&quot;)){
                                                         
                                                            return &quot;success&quot;;
                                     }
                                     else {
                                                            return &quot;error&quot;;
  
                                      }
  
                        }
  
  
  }
  </code></pre>
  <p><strong>And here is my <code>struts.xml</code></strong>:</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;!DOCTYPE struts PUBLIC
  &quot;-//Apache Software Foundation//DTD Struts Configuration 2.0//EN&quot;
  &quot;http://struts.apache.org/dtds/struts-2.0.dtd&quot;&gt;
  &lt;struts&gt;
      &lt;constant name=&quot;struts.devMode&quot; value=&quot;true&quot; /&gt;
      &lt;package name=&quot;default&quot; namespace=&quot;/&quot; extends=&quot;struts-default&quot;&gt;
  
          &lt;interceptors &gt;
              &lt;interceptor name=&quot;uppername&quot; class=&quot;com.interceptor.MyInterceptor&quot;&gt;&lt;/interceptor&gt;
          &lt;/interceptors&gt;
  
          &lt;action name=&quot;login&quot; class=&quot;com.ravi.action.MyAction&quot;&gt;
                  &lt;interceptor-ref name=&quot;uppername&quot;&gt;&lt;/interceptor-ref&gt;
                  &lt;interceptor-ref name=&quot;defaultStack&quot;&gt;&lt;/interceptor-ref&gt;  
  
                  &lt;result name=&quot;success&quot; &gt;welcome.jsp&lt;/result&gt;
                  &lt;result name=&quot;error&quot;&gt;Error.jsp&lt;/result&gt;
          &lt;/action&gt;
  
  &lt;/package&gt;
  &lt;/struts&gt;
  </code></pre>
  <p><strong>And the Stacktrace is as follows:</strong></p>
  <pre class="lang-java prettyprint-override"><code>java.lang.NullPointerException 
      com.interceptor.MyInterceptor.intercept(MyInterceptor.java:14)
      com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245)
      org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
      org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:567)
      org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:81)
      org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)
      org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
      org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
      org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
      org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
      org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
      org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
      org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
      org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
      org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
      org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
      org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2522)
      org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2511)
      java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
      java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:1)
      java.lang.Thread.run(Unknown Source)
  </code></pre>
  <p>I guess the problem lies in accessing the request parameters in the <code>MyInterceptor.java</code>. The <code>ValueStack</code>'s method <code>findString()</code> is not returning the values of parameters <code>name</code> and <code>password</code>.</p>