我在struts2中遇到标签问题。我真的不知道这个标签的执行情况
之前,我在我的数据库中有一个国家/地区列表,我希望将其放入<s:select>
。我试过了
jsp页面(有我的标签):
<s:select headerKey="-1" headerValue="Select Search Engines" list="country" name="yoursearch"></s:select>
动作类:
public class ShowSelect extends ActionSupport{
private List<String> country;
public ShowSelect() {
country = new ArrayList<String>();
country.add("google.com");
country.add("bing.com");
country.add("yahoo.com");
country.add("baidu.com");
}
public String display() {
return "success";
}
public List<String> getSearchEngine() {
return country;
}
public void setSearchEngine(List<String> country) {
this.country = country;
}
}
文件struts.xml
<action name="search" class="controller.ShowSelect">
<result name="success">Select.jsp</result>
</action>
。但是,浏览器出现错误如下:
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: tag 'select', field 'list': The requested list key '' 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:522)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:416)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:389)
root cause
tag 'select', field 'list': The requested list key '' 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:237)
org.apache.struts2.components.Component.findValue(Component.java:358)
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:856)
org.apache.struts2.components.UIBean.end(UIBean.java:510)
org.apache.struts2.views.jsp.ComponentTagSupport.doEndTag(ComponentTagSupport.java:42)
org.apache.jsp.Product.ShowListProduct_jsp._jspx_meth_s_005fselect_005f0(ShowListProduct_jsp.java:253)
org.apache.jsp.Product.ShowListProduct_jsp._jspx_meth_s_005fdiv_005f0(ShowListProduct_jsp.java:115)
org.apache.jsp.Product.ShowListProduct_jsp._jspService(ShowListProduct_jsp.java:70)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:389)
我需要的是:通过Action类从数据库中获取列表
你可以帮帮我吗?请答案 0 :(得分:1)
它显示问题因为你没有吸气剂和动作类列表的setter。
写getCountry()
&amp;你的行动中的setCountry()
方法。它肯定会正常工作。