在webroot根目录下建一个login.jsp文件,在struts.xml文件中配置如下,使其redirect重定向到/user/hello.jsp页面,在webroot根目录下已创建一个文件夹,文件夹中已有hello.jsp。运行报错如下。
<package name="test" extends="struts-default">
<action name="login" class="com.jay.UserAction">
<result type="redirect">/user/hello.jsp</result>
</action>
</package>
<s:form action="login">
<s:textfield name="userName" key="username"></s:textfield>
<s:password name="password" key="password"></s:password>
<s:submit key="login"></s:submit>
</s:form>
严重: Servlet.service() for servlet [jsp] in context with path [/test2] threw exception [java.lang.IllegalArgumentException: can't parse argument number: userName] with root cause
java.lang.NumberFormatException: For input string: "userName"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:492)
at java.lang.Integer.parseInt(Integer.java:527)
at java.text.MessageFormat.makeFormat(MessageFormat.java:1418)
at java.text.MessageFormat.applyPattern(MessageFormat.java:479)
at java.text.MessageFormat.<init>(MessageFormat.java:363)
at com.opensymphony.xwork2.util.LocalizedTextUtil.buildMessageFormat(LocalizedTextUtil.java:704)
at com.opensymphony.xwork2.util.LocalizedTextUtil.findDefaultText(LocalizedTextUtil.java:229)
at com.opensymphony.xwork2.DefaultTextProvider.getText(DefaultTextProvider.java:67)
at com.opensymphony.xwork2.DefaultTextProvider.getText(DefaultTextProvider.java:82)
at com.opensymphony.xwork2.DefaultTextProvider.getText(DefaultTextProvider.java:129)
at org.apache.struts2.util.TextProviderHelper.getText(TextProviderHelper.java:75)
at org.apache.struts2.components.Text.end(Text.java:160)
at org.apache.struts2.views.jsp.ComponentTagSupport.doEndTag(ComponentTagSupport.java:42)
at org.apache.jsp.user.hello_jsp._jspx_meth_s_005ftext_005f1(hello_jsp.java:165)
at org.apache.jsp.user.hello_jsp._jspService(hello_jsp.java:96)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
java.lang.NumberFormatException:Forinputstring:"userName"
高手,求指导!!!!!java.lang.NumberFormatException:Forinputstring:"userName"
你是不是对输入的userName字符串强制转数字了?检查一下,这种都是自己写的程序问题
如果不在struts.xml中配置redirect重定向时,程序是可以运行的类型转换的错误啦。。。 @回忆的沙漏无论如何,谢谢你。回复 @Jay_彦:说实话,我基本都是用的默认的转发,重定向这种我在项目中还真很少用。顶多也就action与action之间的跳转使用过redirectAction作业来着,你可以写个简单例子说明一下redirect用法不回复 @Jay_彦:你将跳转的方式改成chain试试如果不在struts.xml中配置redirect重定向时,是可以运行的换种方式写重定向老师布置的作业来着,得照着做,你可以写个简单的例子来说明以下redirect的用法不?感谢!版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。