在Struts2下拉列表程序中找到错误? [英] Find the error in Struts2 dropdown list program?

查看:32
本文介绍了在Struts2下拉列表程序中找到错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这三个文件是为 struts2 提供的.它没有给出输出.它给出jasper 异常.请找出错误

the three files are given for struts2.it is not giving the output.its giving jasper exception.please find the errors

========================

========================

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 服务器日志的某些部分 */

/*some parts of Glassfish server log */

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)

推荐答案

提供系统抛出的错误/异常总是更好,否则其他人很难告诉任何事情.而且没有人有那么多时间在那里编写程序并查看错误.

its always better to provide the error/exception being thrown by the system else its very hard for the other to tell anything.Moreover no one have that much time to write the programe in there system and see the error.

我对可能的错误的第一次尝试是

my first shot for possible error is

<p:select name="country" list="countryList"  label="Select a country" />

这意味着它将尝试在您的操作类中找到受尊重的 getter 方法 getCountryList() 但您的操作类具有以下方法

which means it will try to find the respected getter method getCountryList() in your action class but your action class have the following method

public  ArrayList getCountrylist()/*getting countrylist*/
 {
 return countrylist;
 }

要么将选择更改为

  <p:select name="country" list="countrylist"  label="Select a country" />

或在您的操作类中进行所需的更正.

or do the required correction in your action class.

始终建议为接口编程而不是实现,这将为您提供更大的灵活性.

Its always advisable to program to interface rather than implementation which will provide you more flexibility.

您可以创建 List 并使用 ArrayList 对其进行初始化.这对我有用

You can create List and initialize it with ArrayList.Here is what is working for me

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");

JSP 类

<s:select name="country" list="countryList"  label="Select a country" />

输出

这篇关于在Struts2下拉列表程序中找到错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆