struts2 ognl 中令人讨厌的 java.lang.NumberFormatException
我遇到了这个令人讨厌的异常,问题是我无法控制获取字符串,因为它是由第三方应用程序完成的。显然,该数字太长,无法解析为 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 snippet:
<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
存储会话参数在线程本地
中。
I'm getting this nasty exception, the problem is that I cannot control the get string since it's done by a 3rd party app. Apparently the number is too long to be parsed as 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 snippet:
<package name="ajax" namespace="/ajax" extends="default">
<default-interceptor-ref name="ajaxStack"/>
<action name="**">
<result>/WEB-INF/ajax/{1}.jsp</result>
</action>
</package>
and the interceptor:
<interceptor-stack name="ajaxStack">
<interceptor-ref name="checkSession" />
<interceptor-ref name="checkAjax" />
<interceptor-ref name="defaultStack" />
</interceptor-stack>
checkAjax
just makes sure the user is logged in and checkSession
stores a session param in a threadlocal
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题不在于 OGNL 解析器,而在于 Integer.parseInt() 方法。当我们向 Integer.parseInt 方法输入一个 String 时,编译时不会检测到该 String 的数值是否是范围内的数字。以下代码将显示编译时错误:
但以下代码将引发运行时异常:
The issue is not with OGNL parser, it's the Integer.parseInt() method. When we input a String to the Integer.parseInt method, it is not detected at compile time if the numeric value of the String is a number in range. The following code will show a compile time error:
But the following will throw a runtime exception: