gpt4 book ai didi

java - Struts2 将列表转换为整数或 double 不起作用

转载 作者:行者123 更新时间:2023-11-30 04:15:02 26 4
gpt4 key购买 nike

我是 Struts2 的新手,并在实践中使用 Struts2 来学习它。我在书中找到了一个示例,它将请求参数映射到列表,同时尝试将参数从默认类型字符串转换为 double 或整数。它假定列表没有类型信息(如 java 5 之前的版本)。我遇到了异常。

Login.jsp

 <s:form  action="LoginAction">
<s:textfield name="username" label="Username"></s:textfield>
<s:password name="password" label="Password"></s:password>
<s:textfield name="age" label="Age"></s:textfield>
<s:textfield name="name" label="First Name"></s:textfield>
<s:textfield name="name" label="Second Name"></s:textfield>
<s:textfield name="name" label="Last Name"></s:textfield>
<s:submit value="Login"></s:submit>
</s:form>

登录操作

package org.shammu.actions;

import java.util.List;

import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class LoginAction extends ActionSupport{

private String username;
private String password;
private int age;
private List name;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public List getName() {
return name;
}
public void setName(List name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}

}

堆栈跟踪

Sep 3, 2013 11:06:22 AM      
com.opensymphony.xwork2.conversion.impl.DefaultConversionFileProcessor error
SEVERE: Problem loading properties for org.shammu.actions.LoginAction
java.lang.InstantiationException: java.lang.Double
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:131)
at com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:162)
at com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:151)
at com.opensymphony.xwork2.conversion.impl.DefaultTypeConverterCreator.
createTypeConverter(DefaultTypeConverterCreator.java:23)
at com.opensymphony.xwork2.conversion.impl.DefaultConversionFileProcessor.
process(DefaultConversionFileProcessor.java:68)
at com.opensymphony.xwork2.conversion.impl.XWorkConverter.addConverterMapping
(XWorkConverter.java:485)
at com.opensymphony.xwork2.conversion.impl.XWorkConverter.buildConverterMapping
(XWorkConverter.java:549)
at com.opensymphony.xwork2.conversion.impl.XWorkConverter.getConverter
(XWorkConverter.java:417)
at com.opensymphony.xwork2.conversion.impl.XWorkConverter.convertValue
(XWorkConverter.java:282)
at com.opensymphony.xwork2.ognl.OgnlTypeConverterWrapper.convertValue
(OgnlTypeConverterWrapper.java:39)
at ognl.OgnlRuntime.getConvertedType(OgnlRuntime.java:1080)
at ognl.OgnlRuntime.getConvertedTypes(OgnlRuntime.java:1097)
at ognl.OgnlRuntime.getConvertedMethodAndArgs(OgnlRuntime.java:1123)
at ognl.OgnlRuntime.getAppropriateMethod(OgnlRuntime.java:1209)
at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:1223)
at ognl.OgnlRuntime.setMethodValue(OgnlRuntime.java:1494)
at ognl.ObjectPropertyAccessor.setPossibleProperty(ObjectPropertyAccessor.java:85)
at ognl.ObjectPropertyAccessor.setProperty(ObjectPropertyAccessor.java:162)
at com.opensymphony.xwork2.ognl.accessor.ObjectAccessor.setProperty
(ObjectAccessor.java:27)
at ognl.OgnlRuntime.setProperty(OgnlRuntime.java:2332)
at com.opensymphony.xwork2.ognl.accessor.CompoundRootAccessor.setProperty
(CompoundRootAccessor.java:78)
at ognl.OgnlRuntime.setProperty(OgnlRuntime.java:2332)
at ognl.ASTProperty.setValueBody(ASTProperty.java:127)
at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:220)
at ognl.SimpleNode.setValue(SimpleNode.java:301)
at ognl.Ognl.setValue(Ognl.java:737)
at com.opensymphony.xwork2.ognl.OgnlUtil.setValue(OgnlUtil.java:234)
at com.opensymphony.xwork2.ognl.OgnlValueStack.trySetValue(OgnlValueStack.java:183)
at com.opensymphony.xwork2.ognl.OgnlValueStack.setValue(OgnlValueStack.java:170)
at com.opensymphony.xwork2.ognl.OgnlValueStack.setParameter
(OgnlValueStack.java:148)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.setParameters
(ParametersInterceptor.java:318)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept
(ParametersInterceptor.java:231)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept
(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke
(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept
(ParametersInterceptor.java:239)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept
(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke
(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept
(StaticParametersInterceptor.java:191)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke
(DefaultActionInvocation.java:246)
at org.apache.struts2.interceptor.MultiselectInterceptor.intercept
(MultiselectInterceptor.java:73)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke
(DefaultActionInvocation.java:246)
at org.apache.struts2.interceptor.CheckboxInterceptor.intercept
(CheckboxInterceptor.java:91)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke
(DefaultActionInvocation.java:246)
at org.apache.struts2.interceptor.FileUploadInterceptor.intercept
(FileUploadInterceptor.java:252)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke
(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept
(ModelDrivenInterceptor.java:100)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke
(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept
(ScopedModelDrivenInterceptor.java:141)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke
(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept
(ChainingInterceptor.java:145)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke
(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept
(PrepareInterceptor.java:171)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept
(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke
(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept
(I18nInterceptor.java:161)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke
(DefaultActionInvocation.java:246)
at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept
(ServletConfigInterceptor.java:164)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke
(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept
(AliasInterceptor.java:193)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke
(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept
(ExceptionMappingInterceptor.java:189)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke
(DefaultActionInvocation.java:246)
at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:563)
at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction
(ExecuteOperations.java:77)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter
(StrutsPrepareAndExecuteFilter.java:99)
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:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke
(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service
(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process
(AbstractHttp11Processor.java:1023)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process
(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

这里,我的转换文件放置在操作类的同一文件夹中,是 LoginAction-conversion.properties,其中有一行 Element-name=java.lang.Double。帮帮我

最佳答案

这应该是 Element_name=java.lang.Double

关于java - Struts2 将列表转换为整数或 double 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18585274/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com