请求的列表密钥'许可证'无法解决

时间:2016-05-03 10:09:41

标签: jsp struts2 web.xml

LicenseCheckBoxAction.java:

import java.util.ArrayList;
import java.util.List;

import com.opensymphony.xwork2.ActionSupport;

public class LicenseCheckBoxAction extends ActionSupport{


    private List<String> license;

    private String yourLicense;

    public String LicenseCheckBoxAction() {

        license = new ArrayList<String>();
        license.add("red");
        license.add("yellow");
        license.add("blue");
        license.add("green");
        return NONE;


    }

    public String execute() {
        return SUCCESS;
    }

    public List<String> getLicense() {
        return license;
    }

    public void setLicense(List<String> license) {
        this.license = license;
    }

    public String getYourLicense() {
        return yourLicense;
    }

    public void setYourLicense(String yourLicense) {
        this.yourLicense = yourLicense;
    }

    public String[] getDefaultLicense() {
        return new String[] { "red", "green" };
    }

    public void setYourColor(String yourLicense) {
        this.yourLicense = yourLicense;
        System.out.println(yourLicense);
    }

    public String display() {

        license = new ArrayList<String>();
        license.add("red");
        license.add("yellow");
        license.add("blue");
        license.add("green");
        return NONE;
    }

    }

struts.xml中

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<package name="myPack" extends="struts-default">

<action name="eventInsertAction" class="com.ca.actions.EventInsertAction">
        <result name="success">Success.jsp</result>
        <result name="error">Error.jsp</result>
    </action>
<action name="checkboxListing" class="com.ca.actions.LicenseCheckBoxAction"
        method="LicenseCheckBoxAction">
        <result name="none">create_event.jsp</result>
    </action>
<action name="LicenseCheckBoxAction"                     
class="com.ca.actions.LicenseCheckBoxAction">
<result name="success">Success.jsp</result>
    </action>

</package>
</struts>

的web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID" version="3.1">
<display-name>staff_struts</display-name>
<filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
    <filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter                  
</filter>
<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

create_event.jsp                                                            问题                         许可证                              

异常

HTTP Status 500 - tag 'checkboxlist', field 'list', name 'yourLicense': The 

requested list key 'license' could not be resolved as a

collection/array/map/enumeration/iterator type. Example: people or people.{name} - [unknown location]

type Exception report

message tag 'checkboxlist', field 'list', name 'yourLicense': The requested list key 'license' could not be resolved as a collection/array/map/enumeration/iterator type. Example: people or people.{name} - [unknown location]

description The server encountered an internal error that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: tag 'checkboxlist', field 'list', name 'yourLicense': The requested list key 'license' could not be resolved as a collection/array/map/enumeration/iterator type. Example: people or people.{name} - [unknown location]
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:591)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:476)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:96)
root cause

tag 'checkboxlist', field 'list', name 'yourLicense': The requested list key 'license' could not be resolved as a collection/array/map/enumeration/iterator type. Example: people or people.{name} - [unknown location]
    org.apache.struts2.components.Component.fieldError(Component.java:257)
    org.apache.struts2.components.Component.findValue(Component.java:350)
    org.apache.struts2.components.ListUIBean.evaluateExtraParams(ListUIBean.java:82)
    org.apache.struts2.components.CheckboxList.evaluateExtraParams(CheckboxList.java:67)
    org.apache.struts2.components.UIBean.evaluateParams(UIBean.java:893)
    org.apache.struts2.components.UIBean.end(UIBean.java:535)
    org.apache.struts2.views.jsp.ComponentTagSupport.doEndTag(ComponentTagSupport.java:42)
    org.apache.jsp.create_005fevent_jsp._jspx_meth_s_005fcheckboxlist_005f0(create_005fevent_jsp.java:734)
    org.apache.jsp.create_005fevent_jsp._jspx_meth_s_005fform_005f1(create_005fevent_jsp.java:693)
    org.apache.jsp.create_005fevent_jsp._jspService(create_005fevent_jsp.java:247)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:96)
note The full stack trace of the root cause is available in the Apache Tomcat/8.0.33 logs.

Apache Tomcat/8.0.33

当我尝试使用链接http://localhost:9999/ChaitanyaArtsViews/create_event.jsp调用JSP时,我得到了上述异常,但是当我尝试使用http://localhost:9999/ChaitanyaArtsViews/checkboxListing.action调用该操作时,将显示JSP。如何在没有动作名称的情况下直接调用JSP,因为JSP与其他人链接,因此应该调用它而不是动作?

1 个答案:

答案 0 :(得分:1)

不要直接调用JSP!使用操作方法返回指定JSP位置的调度程序类型结果。

将以下代码添加到web.xml,以便不再使用此类链接。

  <!-- Restricts access to pure JSP files - access available only via Struts action -->
  <security-constraint>
    <display-name>No direct JSP access</display-name>
    <web-resource-collection>
      <web-resource-name>No-JSP</web-resource-name>
      <url-pattern>*.jsp</url-pattern>
    </web-resource-collection>
    <auth-constraint>
      <role-name>no-users</role-name>
    </auth-constraint>
  </security-constraint>

  <security-role>
    <description>Don't assign users to this role</description>
    <role-name>no-users</role-name>
  </security-role>