Java struts 2选择标记异常

Java struts 2选择标记异常,java,drop-down-menu,struts2,Java,Drop Down Menu,Struts2,我有一个dropdownlist,需要使用Struts2Select标记填充它。我得到以下例外。错在哪里 <s:select label="Country" headerKey="-1" headerValue="Select Country" list="countries" listKey="key" listValue="label" name="searchForm.cust

我有一个dropdownlist,需要使用Struts2Select标记填充它。我得到以下例外。错在哪里

    <s:select label="Country" headerKey="-1" headerValue="Select Country" list="countries"  
                                                listKey="key" listValue="label" name="searchForm.custCountry"/> 

在我的action类中,我有以下声明,后面是getter和setter

    ArrayList<DropDown> countries = new ArrayList<DropDown>();


    SEVERE: Servlet.service() for servlet jsp threw exception
    tag 'select', field 'list', name 'searchForm.custCountry': The requested list key 'countries' could not be resolved as a collection/array/map/enumeration/iterator type. Example: people or people.{name} - [unknown location]
        at org.apache.struts2.components.Component.fieldError(Component.java:240)
        at org.apache.struts2.components.Component.findValue(Component.java:333)
        at org.apache.struts2.components.ListUIBean.evaluateExtraParams(ListUIBean.java:80)
        at org.apache.struts2.components.Select.evaluateExtraParams(Select.java:105)
        at org.apache.struts2.components.UIBean.evaluateParams(UIBean.java:902)
        at org.apache.struts2.components.UIBean.end(UIBean.java:544)
        at org.apache.struts2.views.jsp.ComponentTagSupport.doEndTag(ComponentTagSupport.java:42)
        at org.apache.jsp.accountSearchDtls_jsp._jspx_meth_s_005fselect_005f0(accountSearchDtls_jsp.java:979)
        at org.apache.jsp.accountSearchDtls_jsp._jspx_meth_s_005fdiv_005f0(accountSearchDtls_jsp.java:935)
        at org.apache.jsp.accountSearchDtls_jsp._jspService(accountSearchDtls_jsp.java:521)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:96)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
        at java.lang.Thread.run(Thread.java:745)
ArrayList countries=new ArrayList();
严重:Servlet jsp的Servlet.service()引发异常
标记“select”、字段“list”、名称“searchForm.custCountry”:无法将请求的列表键“countries”解析为集合/数组/映射/枚举/迭代器类型。示例:人或人。{name}-[未知位置]
位于org.apache.struts2.components.Component.fieldError(Component.java:240)
位于org.apache.struts2.components.Component.findValue(Component.java:333)
位于org.apache.struts2.components.ListUIBean.evaluateExtraParams(ListUIBean.java:80)
位于org.apache.struts2.components.Select.evaluateExtraParams(Select.java:105)
位于org.apache.struts2.components.UIBean.evaluateParams(UIBean.java:902)
位于org.apache.struts2.components.UIBean.end(UIBean.java:544)
位于org.apache.struts2.views.jsp.ComponentTagSupport.doEndTag(ComponentTagSupport.java:42)
在org.apache.jsp.accountSearchDtls\u jsp.\u jspx\u meth\u s\u 005fselect\u 005f0(accountSearchDtls\u jsp.java:979)
在org.apache.jsp.accountSearchDtls\u jsp.\u jspx\u meth\u s\u 005fdiv\u 005f0(accountSearchDtls\u jsp.java:935)
在org.apache.jsp.accountSearchDtls\u jsp.\u jsp服务(accountSearchDtls\u jsp.java:521)
位于org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
位于javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
位于org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
位于org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
位于org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
位于javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
位于org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
位于org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
位于org.apache.struts2.dispatcher.ng.filter.strutspreadexecutefilter.doFilter(strutspreadexecutefilter.java:96)
位于org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
位于org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
位于org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
位于org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
位于org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
位于org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
位于org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
位于org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
位于org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
位于org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
位于org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
运行(Thread.java:745)
下面是我获取下拉列表数据的方法。我有这个就够了,如果不让我知道

public ArrayList<DropDown> getCountrydd() {
        ArrayList<DropDown> countrydd = new ArrayList<DropDown>();
        try {
            OraConn conn = new OraConn();
            conn.getConnection();
            cstmt = conn.setProc("call mgm.getCountry(?)");
               cstmt.registerOutParameter(1, OracleTypes.CURSOR);
               cstmt.execute();
         rs = (OracleResultSet)cstmt.getObject(1);
               countrydd = rsToDropDown(rs);

        } catch (Exception e) {
               e.printStackTrace();
               //log.error("***getDSdropdowns*** ");
        } finally {
            closeORAConnection();
        }
        return countrydd;
    }
public ArrayList getCountrydd(){
ArrayList countrydd=新的ArrayList();
试一试{
OraConn=新的OraConn();
连接getConnection();
cstmt=conn.setProc(“调用mgm.getCountry(?);
cstmt.registerOutParameter(1,OracleTypes.CURSOR);
cstmt.execute();
rs=(OracleResultSet)cstmt.getObject(1);
countrydd=rsToDropDown(rs);
}捕获(例外e){
e、 printStackTrace();
//log.error(“***getDSdropdowns***”);
}最后{
closeORAConnection();
}
返回国DD;
}

您需要更改代码以填充列表

public ArrayList<DropDown> getCountrydd() {

    List<DropDown> countrydd = new ArrayList<DropDown>();
    OraConn oraConn = new OraConn();
    Connection conn = null;
    CallableStatement cstmt = null;
    ResultSet rs = null;
    try {
        conn = oraConn.getConnection();
        cstmt = conn.prepareCall("{call mgm.getCountry(?)}");
        cstmt.registerOutParameter(1, OracleTypes.CURSOR);
        cstmt.executeUpdate();
        rs = (ResultSet)cstmt.getObject(1);

        rsToDropDown(rs, countrydd);

    } catch (Exception e) {
           e.printStackTrace();
           //log.error("***getDSdropdowns*** ");
    } finally {
        if (rs != null) 
            rs.close();              
        if (cstmt!= null) 
            cstmt.close();               
        if (conn != null) 
            conn.close();                   
    }
    return countrydd;
}
public ArrayList getCountrydd(){
List countrydd=new ArrayList();
OraConn OraConn=新的OraConn();
连接conn=null;
CallableStatement cstmt=null;
结果集rs=null;
试一试{
conn=oraConn.getConnection();
cstmt=conn.prepareCall({call mgm.getCountry(?)});
cstmt.registerOutParameter(1,OracleTypes.CURSOR);
cstmt.executeUpdate();
rs=(ResultSet)cstmt.getObject(1);
rsToDropDown(rs、countrydd);
}捕获(例外e){
e、 printStackTrace();
//log.error(“***getDSdropdowns***”);
}最后{
如果(rs!=null)
rs.close();
如果(cstmt!=null)
cstmt.close();
如果(conn!=null)
康涅狄格州关闭();
}
返回国DD;
}

我发现,即使用户为空,我也在用国家/地区值填充组合框或下拉列表,因此,当我单击“创建新用户”按钮时,我得到了这些异常。现在我更改了代码,现在是这样:

public String getProfile() throws Exception {

    user_name =(String) sessionMap.get("userid") ;

    MgmService service = new MgmService();
    userForm = new User();
    userForm = service.getUsersProfile(user_name);

    if(searched_user_name!=null){
        userForm = service.getUsersProfile(searched_user_name);
        countries= service.getCountrydd(); //This keep the content of the combobox by default on the list
        return "createEditUser";
    }
    else if(userForm!=null)
    {
        return "success";
    }

    else {
        addActionError("Invalid Login.");
        return "success";
    }
}
这是我以前的错误代码

public String getProfile() throws Exception {

    user_name =(String) sessionMap.get("userid") ;

    MgmService service = new MgmService();
    userForm = new User();

    userForm = service.getUsersProfile(user_name);
    countries= service.getCountrydd(); //This keep the content of the combobox by default on the list
    if(searched_user_name!=null){
        userForm = service.getUsersProfile(searched_user_name);
        return "createEditUser";
    }
    else if(userForm!=null)
    {
        return "success";
    }

    else {
        addActionError("Invalid Login.");
        return "success";
    }
}

在代码中显示您是如何填写列表的。这是调用一个存储过程,该过程返回一个包含结果的列表。我写这篇文章是因为你的代码有很多bug。