通过jsp将Vector从一个Action发送到另一个Action时出错

时间:2014-05-14 06:22:50

标签: java jsp struts

我正在使用Struts 1.我需要通过jsp将一个Action的对象发送到另一个Action。 在Action1中: 定义的矢量Vector<UserObject> allEligibleUserList = new Vector<UserObject>();  并在添加对象request.setAttribute("elligible", allEligibleUserList);

之后

在jsp中: <html:hidden property="userVector" value="${elligible}" />

表格:

private Vector<UserObject> userVector;
public Vector<UserObject> getUserVector() {
    return userVector;
}

public void setUserVector(Vector<UserObject> userVector) {
    this.userVector = userVector;
}

在Action2中: Vector<UserObject> elligibleUserVector = catalogForm.getUserVector();

但是我收到以下错误:

SEVERE: Servlet.service() for servlet [action] in context with path [/MetalWeb] threw exception [BeanUtils.populate] with root cause
java.lang.IllegalArgumentException: argument type mismatch
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.commons.beanutils.PropertyUtils.setSimpleProperty(PropertyUtils.java:1789)
    at org.apache.commons.beanutils.PropertyUtils.setNestedProperty(PropertyUtils.java:1684)
    at org.apache.commons.beanutils.PropertyUtils.setProperty(PropertyUtils.java:1713)
    at org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:1019)
    at org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:808)
    at org.apache.struts.util.RequestUtils.populate(RequestUtils.java:1252)
    at org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.java:821)
    at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:254)
    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
    at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at com.mj.metal.filters.AutoLoggingFilter.doFilter(AutoLoggingFilter.java:60)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at com.mj.metal.filters.AutoXSSFilter.doFilter(AutoXSSFilter.java:59)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at com.mj.metal.filters.CSRFGuardFilter.doFilter(CSRFGuardFilter.java:59)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    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:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    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:409)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1044)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:315)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

我做错了什么以及如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

请求属性仅接受String或String数组。 因此,要通过jsp将数据从一个动作传输到另一个动作,您应该将其设置为如下的会话属性:

request.getSession().setAttribute("elligible", allEligibleUserList);

并在下一个操作类中获取属性并将其删除如下:

Vector<UserObject> elligibleUserVector = (Vector<UserObject>) request.getSession().getAttribute("elligible");
request.getSession().removeAttribute("elligible");