0

chain.doFilter(request, response); 実行すると以下のエラーが発生します 。このエラーは時々発生します。

スタック トレースは次のとおりです::

enter code here

<i>javax.servlet.ServletException: For input string: "NULL"
    at org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:516)
    at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:423)
    at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)
    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
    at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:397)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:835)
    at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:341)
    at com.evermind.server.http.ServletRequestDispatcher.forward(ServletRequestDispatcher.java:261)
    at com.evermind.server.http.GetParametersRequestDispatcher.forward(GetParametersRequestDispatcher.java:257)
    at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1056)
    at org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:388)
    at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:231)
    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
    at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:397)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at com.evermind.server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:65)
    at my.SampleFilter.doFilter(SampleFilter.java:120)
    at com.evermind.server.http.EvermindFilterChain.doFilter(EvermindFilterChain.java:16)
    at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:176)
    at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145)
    at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92)
    at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:381)
    at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:670)
    at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:341)
    at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:816)
    at com.evermind.server.http.AJPRequestHandler.run(AJPRequestHandler.java:231)
    at com.evermind.server.http.AJPRequestHandler.run(AJPRequestHandler.java:136)
    at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:186)
    at java.lang.Thread.run(Thread.java:534)</i>

私のフィルターコードは以下の通りです::

<i>public class SampleFilter
implements Filter
{

private transient FilterConfig filterConfig;
Context initialContext;

public SampleFilter()
{
    filterConfig = null;
    initialContext = null;
}

public void destroy()
{
}



public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
    throws ServletException, IOException
{



    Connection conn=getJNDIConnection();

    request.setAttribute("CONNECTION", conn);
    try
    {
        System.out.println("Filter start GOOG Website");
        chain.doFilter(request, response);
    }
    catch(Exception e)
    {
        //System.out.println("@@@@@@@@@@@@@@@@@@@@@ Exception occured in doFilter @@@@@@@@@@@@@@@");
        closeConnection(initialContext, conn);
        System.out.println("@@@@@@@@@@@@@@@@@@@@@ Connection Closed @@@@@@@@@@@@@@@");

        String fullStackTrace = org.apache.commons.lang.exception.ExceptionUtils.getFullStackTrace(e);



        e.printStackTrace();
    }
    closeConnection(initialContext, conn);
    System.out.println("Filter end ");
}

Connection getJNDIConnection()
{
    Connection conn = null;
    try
    {
        initialContext = new InitialContext();
        if(initialContext == null)
        {
            System.out.println("JNDI problem. Cannot get InitialContext.");
        }
        DataSource datasource = (DataSource)initialContext.lookup("jdbc/MY_DS");
        if(datasource != null)
        {
            conn = datasource.getConnection();
        } else
        {
            System.out.println("Failed to lookup datasource.");
        }
    }
    catch(NamingException ex)
    {
        System.out.println("Cannot get connection: " + ex);
    }
    catch(SQLException ex)
    {
        System.out.println("Cannot get connection: " + ex);
    }
    return conn;
}



void closeConnection(Context ctx, Connection conn) {
    try {
        if (ctx != null) {
            ctx.close();
            ctx = null;
        }

        if (conn != null && !conn.isClosed()) {
            conn.close();
            conn = null;
        }
    } catch (NamingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (SQLException sqe) {
        sqe.printStackTrace();
    } finally {
        conn = null;
    }
}

public void init(FilterConfig filterConfig)
    throws ServletException
{
    this.filterConfig = filterConfig;
}
}
</i>

私のweb.xmlの内容は以下の通りです::

<i><?xml version="1.0" encoding="UTF-8"?>
<web-app>
  <servlet>
    <servlet-name>action</servlet-name>
    <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
    <init-param>
      <param-name>config</param-name>
      <param-value>/WEB-INF/struts-config.xml</param-value>
    </init-param>
    <init-param>
      <param-name>debug</param-name>
      <param-value>3</param-value>
    </init-param>
    <init-param>
      <param-name>detail</param-name>
      <param-value>3</param-value>
    </init-param>
    <load-on-startup>0</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.do</url-pattern>
  </servlet-mapping>



  <filter>
     <filter-name>UrlRewriteFilter</filter-name>
     <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
  </filter>

  <filter-mapping>
    <filter-name>UrlRewriteFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>


    <filter>
        <filter-name>SampleFilter</filter-name>
        <filter-class> my.SampleFilter
        </filter-class>
    </filter>

    <filter-mapping>
        <filter-name>SampleFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

     <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>

     <session-config>
      <session-timeout>720</session-timeout> 
    </session-config>

</web-app>
</i>

ありがとう

4

1 に答える 1

0

ここで誤解が生じています。

javax.servlet.ServletException: For input string: "NULL"
    at org.apache.struts.action.RequestProcessor.processException

この例外はフィルターが原因ではありませんが、他の場所で発生してスローさtry-catchれ、フィルター内のブロックが誤った方法で例外を処理するまでキャッチされません。合理的に対処できる例外のみをキャッチする必要があります。合理的に対処できる例外は明らかに1つもないため、これらの例外を通過させて、catchブロック全体を完全に削除し、finally.

Connection conn = getJNDIConnection();
request.setAttribute("CONNECTION", conn);

try {
    chain.doFilter(request, response);
} finally {
    closeConnection(initialContext, conn);
}

特定の例外に戻りますが、これは別の場所で発生すると言われています。スタック トレースが不完全なので、大まかな推測を行います。文字列値を含む数値フィールドをどこかで入力していて"NULL"、それに対して がスローNumberFormatExceptionされています。この問題の解決策は明らかです。文字列値を入力しないか"NULL"、数値フィールドではなく文字列フィールドにします。

于 2012-07-09T15:38:33.973 に答える