0

我遇到了这个讨厌的异常,问题是我无法控制 get 字符串,因为它是由 3rd 方应用程序完成的。显然数字太长而无法解析为int ...

java.lang.NumberFormatException: For input string: "1286579871769"
        at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
        at java.lang.Integer.parseInt(Integer.java:461)
        at java.lang.Integer.valueOf(Integer.java:528)
        at ognl.OgnlParserTokenManager.makeInt(OgnlParserTokenManager.java:63)
        at ognl.OgnlParserTokenManager.TokenLexicalActions(OgnlParserTokenManager.java:1624)
        at ognl.OgnlParserTokenManager.getNextToken(OgnlParserTokenManager.java:1498)
        at ognl.OgnlParser.jj_ntk(OgnlParser.java:3099)
        at ognl.OgnlParser.unaryExpression(OgnlParser.java:1079)
        at ognl.OgnlParser.multiplicativeExpression(OgnlParser.java:971)
        at ognl.OgnlParser.additiveExpression(OgnlParser.java:894)
        at ognl.OgnlParser.shiftExpression(OgnlParser.java:750)
        at ognl.OgnlParser.relationalExpression(OgnlParser.java:508)
        at ognl.OgnlParser.equalityExpression(OgnlParser.java:405)
        at ognl.OgnlParser.andExpression(OgnlParser.java:352)
        at ognl.OgnlParser.exclusiveOrExpression(OgnlParser.java:299)
        at ognl.OgnlParser.inclusiveOrExpression(OgnlParser.java:246)
        at ognl.OgnlParser.logicalAndExpression(OgnlParser.java:193)

struts2 片段:

<package name="ajax" namespace="/ajax" extends="default">

        <default-interceptor-ref name="ajaxStack"/>

        <action name="**">
            <result>/WEB-INF/ajax/{1}.jsp</result>
        </action>

    </package>

和拦截器:

<interceptor-stack name="ajaxStack">                        
                <interceptor-ref name="checkSession" />
                <interceptor-ref name="checkAjax" />    
                <interceptor-ref name="defaultStack" />                                 
            </interceptor-stack>

checkAjax只需确保用户已登录并将checkSession会话参数存储在threadlocal.

4

1 回答 1

0

问题不在于 OGNL 解析器,而是 Integer.parseInt() 方法。当我们在 Integer.parseInt 方法中输入 String 时,如果 String 的数值是范围内的数字,则在编译时不会检测到。以下代码将显示编译时错误:

Integer y = new Integer(3223232320); 

但以下将引发运行时异常:

Integer y = new Integer("3223232320");
于 2010-10-09T06:49:46.407 回答