为struts2.it提供了三个文件,没有给出output.its给出 jasper exception.please找到错误
========================
updatedesig.jsp
=======================
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="p" uri="/struts-tags" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<p:form action="count"method="post">
<p:select name="country" list="countryList" label="Select a country" />/*creating list in jsp*/
</p:form>
<h1>Hello World!</h1>
</body>
</html>
========================
struts.xml
========================
<struts>
<package name="b" extends="struts-default">
<action name="count" class="b.Countr" >/*action class is Countr.java*/
<result name="success">updatedesig.jsp</result>
</action>
</package>
</struts>
============================
Countr.java
============================
package b;
import java.util.ArrayList;
import com.opensymphony.xwork2.ActionSupport;
public class Countr extends ActionSupport/*class Countr*/
{
public ArrayList countrylist;
String country;
public ArrayList getCountrylist()/*getting countrylist*/
{
return countrylist;
}
public void setCountrylist( ArrayList countrylist)/*setting countrylist*/
{
this.countrylist=countrylist;
}
public String getCountry()/*getting country*/
{
return country;
}
public void setCountry( String country)/*setting country*/
{
this.country=country;
}
public String execute()
{
countrylist = new ArrayList();/*creating the arraylist*/
countrylist.add("1");
countrylist.add("!");
countrylist.add("1");
return SUCCESS;
}
}
/ * Glassfish服务器日志的某些部分* /
WARNING: StandardWrapperValve[jsp]: PWC1406: Servlet.service() for servlet jsp threw exception
tag 'select', field 'list', name 'country': The requested list key 'countryList' 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:237)
at org.apache.struts2.components.Component.findValue(Component.java:358)
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:856)
at org.apache.struts2.components.UIBean.end(UIBean.java:510)
at org.apache.struts2.views.jsp.ComponentTagSupport.doEndTag(ComponentTagSupport.java:42)
at org.apache.jsp.updatedesig_jsp._jspx_meth_p_select_0(updatedesig_jsp.java:138)
at org.apache.jsp.updatedesig_jsp._jspx_meth_p_form_0(updatedesig_jsp.java:107)
at org.apache.jsp.updatedesig_jsp._jspService(updatedesig_jsp.java:68)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:403)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:492)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:378)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1539)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:88)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)
at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:330)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:174)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:725)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1019)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:722)
答案 0 :(得分:2)
总是更好地提供系统抛出的错误/异常,其他人很难告诉任何东西。而且没有人有那么多时间在那里编写程序并看到错误。
我可能出错的第一个镜头是
<p:select name="country" list="countryList" label="Select a country" />
这意味着它会尝试在您的操作类中找到受尊重的getter方法getCountryList()
,但您的操作类具有以下方法
public ArrayList getCountrylist()/*getting countrylist*/
{
return countrylist;
}
将选择更改为
<p:select name="country" list="countrylist" label="Select a country" />
或在您的动作类中进行必要的更正。
总是建议编程接口而不是实现,这将为您提供更大的灵活性。
您可以创建List
并使用ArrayList
对其进行初始化。以下是适用于我的内容
List<String> countryList;
public List<String> getCountryList() {
return countryList;
}
public void setCountryList(List<String> countryList) {
this.countryList = countryList;
}
countryList=new ArrayList<String>();
countryList.add("1");
countryList.add("!");
countryList.add("1");
<s:select name="country" list="countryList" label="Select a country" />