来帮我看看这个html:options的小程序怎么老是出错,在线等,

bigbluewhale bigbluewhale 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我想用struts做一个html:options的小程序,老是提示我找不到collection,大家来看看是怎么回事。

jsp页面是这样的

<html:html locale="true">
<head>
<title>
jsp1
</title>
<html:base/>
</head>
<body>

<p>
<html:form action="/untitled1Action.do" method="POST">
<html:text property="userName"/>

<html:select property="hobby">
<html:optionsCollection name="untitled1ActionForm" property="hobbies" label=" label" value="value" />
</html:select>
<br>
<html:submit property="submit" value="Submit"/><br>
<html:reset value ="Reset"/>
</html:form>
</body>
</html:html>

ActionForm是这样的

package untitled11;

import org.apache.struts.action.*;
import javax.servlet.http.*;
import java.util.Collection;
import java.util.Vector;

public class Untitled1ActionForm extends ActionForm {

public void Untitiled1ActionForm(){
Hobby hobby = new Hobby("label1", "value1");
hobbies.add(hobby);
hobby = null;
hobby = new Hobby("label2", "value2");
hobbies.add(hobby);
hobby = null;
hobby = new Hobby("label3", "value3");
hobbies.add(hobby);
hobby = null;

}

private String userName;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}

private Collection hobbies = new Vector();
public void setHobbies(Collection hobbies){
this.hobbies = hobbies;
}

public Collection getHobbies(){
return this.hobbies;
}

private String hobby;
public void setHobby(String hobby){
this.hobby = hobby;
}

public String getHobby(){
return this.hobby;
}

public ActionErrors validate(ActionMapping actionMapping, HttpServletRequest httpServletRequest) {
/**@todo: finish this method, this is just the skeleton.*/
return null;
}
public void reset(ActionMapping actionMapping, HttpServletRequest httpServletRequest) {
}
}

class Hobby{
private String label = "";
private String value = "";

public Hobby(String label, String value){
this.label = label;
this.value = value;
}

public void setLabel(String label){
this.label = label;
}

public String getLabel(){
return this.label;
}

public void setValue(String value){
this.value = value;
}

public String getValue(){
return this.value;
}
}


struts-config.xml是这样的
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config>
<form-beans>
<form-bean name="untitled1ActionForm" type="untitled11.Untitled1ActionForm" />
</form-beans>
<action-mappings>
<action input="/jsp1.jsp" name="untitled1ActionForm" path="/untitled1Action" scope="request" type="untitled11.Untitled1Action" validate="false" />
</action-mappings>
</struts-config>


出错信息如下:


javax.servlet.jsp.JspException: Failed to obtain specified collection
at org.apache.struts.taglib.html.OptionsCollectionTag.doStartTag(OptionsCollectionTag.java:222)
at jsp_servlet.__jsp1._jspService(__jsp1.java:253)
at weblogic.servlet.jsp.JspBase.service(JspBase.java:33)
at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:1053)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:387)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:305)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6310)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:317)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118)
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3622)
at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2569)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)


谢谢各位指点了!
...全文

相关推荐

评论 2
收藏 已收藏
分享
返回顶部
bigbluewhale
Web 开发 81,107 成员 341,720 内容