将Map加载到jsp中以填充struts2中的下拉列表

时间:2017-03-23 07:36:41

标签: struts2

在我的工作中,我必须维护一些先前开发人员编写的Web应用程序,最近我必须将Struts从2.1.6升级到2.3.32

更新进展顺利,我在应用程序中唯一真正的改变是改变旧的

<filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>

<filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
web.xml 中的

,但现在的问题是,应用程序填充的每个下拉列表都会失败并显示相同的异常,例如:

mars 23, 2017 8:14:03 AM org.apache.catalina.core.ApplicationDispatcher invoke
GRAVE: "Servlet.service()" pour la servlet jsp a lancé une exception
tag 'select', field 'list', name 'QUALITE': The requested list key 'liste_Qualite' 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:263)
    at org.apache.struts2.components.Component.findValue(Component.java:356)
    at org.apache.struts2.components.ListUIBean.evaluateExtraParams(ListUIBean.java:82)
    at org.apache.struts2.components.Select.evaluateExtraParams(Select.java:105)
    at org.apache.struts2.components.UIBean.evaluateParams(UIBean.java:893)
    at org.apache.struts2.components.UIBean.end(UIBean.java:535)
    at org.apache.struts2.views.jsp.ComponentTagSupport.doEndTag(ComponentTagSupport.java:42)
    ...



mars 23, 2017 8:14:03 AM org.apache.struts2.dispatcher.DefaultDispatcherErrorHandler error
GRAVE: Exception occurred during processing request: tag 'select', field 'list', name 'QUALITE': The requested list key 'liste_Qualite' could not be resolved as a collection/array/map/enumeration/iterator type. Example: people or people.{name} - [unknown location]
org.apache.jasper.JasperException: tag 'select', field 'list', name 'QUALITE': The requested list key 'liste_Qualite' could not be resolved as a collection/array/map/enumeration/iterator type. Example: people or people.{name} - [unknown location]
    at org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:538)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:430)
    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)
    ...



mars 23, 2017 8:14:03 AM org.apache.catalina.core.StandardWrapperValve invoke
GRAVE: "Servlet.service()" pour la servlet default a généré une exception
java.lang.IllegalStateException
    at org.apache.catalina.connector.ResponseFacade.sendError(ResponseFacade.java:407)
    at org.apache.struts2.dispatcher.DefaultDispatcherErrorHandler.sendErrorResponse(DefaultDispatcherErrorHandler.java:80)
    at org.apache.struts2.dispatcher.DefaultDispatcherErrorHandler.handleError(DefaultDispatcherErrorHandler.java:59)
    at org.apache.struts2.dispatcher.Dispatcher.sendError(Dispatcher.java:920)
    at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:587)
    at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:81)
    at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)
    ...

最后一个Exception让我觉得问题来自web.xml中过滤器的更改,因为应用程序的其余部分尚未修改。但经过一天的搜索,我似乎无法找到如何使应用程序再次运行。

Map已初始化并填写在此文件中:

public class OrdreMissionAction_ext extends ActionSupport {
    ...
    Map<String,String> liste_Qualite = new HashMap<String,String>();
    public Map<String,String> getliste_Qualite() {
        return liste_Qualite;
    }
    ...
    public String init_om() throws NamingException, IOException{
        liste_Qualite = new LinkedHashMap<String,String>();      
        liste_Qualite.put("IAT","Personnel IATSS");
        liste_Qualite.put("PSD","Personnel uB Postdoctorant");
        liste_Qualite.put("ENS","Personnel uB Ens/Chercheur"); 
        ....
        return SUCCESS;
    }
    ...
}

struts.xml 声明:

<package name="actions_ext"  namespace="/gom_ext" extends="struts-default">
    <default-action-ref name="saisir_Om"></default-action-ref>  
    <action name="saisir_Om" class="beansActions.OrdreMissionAction_ext" method="init_om">
        <interceptor-ref name="StackForms"/>
        <result name="success">/WEB-INF/gom_ext/saisir_Om.jsp</result>
    </action>
    ...
</package>

用这种方式调用jsp:

<s:select label="Choisissez une qualité" headerKey="" headerValue="Choisissez une qualité" list="liste_Qualite" name="QUALITE" id="QUALITE" tabindex="3" onchange="Collab_ext(this.value)"/>

在查看了无数个例子和问题后,我没有看到这些声明中的任何错误,我仍然没有找到解决方法。你知道出了什么问题吗?

通过它的动作http://example.com/gom_ext/saisir_Om调用页面,因此调用init_om()函数并填充Map。

在异常发生之前,应用程序开始发送到浏览器,如果我删除选择,页面似乎正常工作。看起来唯一的问题就是jsp在检索不同列表方面没有成功。

1 个答案:

答案 0 :(得分:0)

好吧,只需改变

getliste_Qualite

getListe_Qualite

很高兴为您提供帮助; - )