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

bigbluewhale 2004-09-19 01:50:59
我想用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)


谢谢各位指点了!
...全文
94 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
bigbluewhale 2004-09-19
  • 打赏
  • 举报
回复
up
bigbluewhale 2004-09-19
  • 打赏
  • 举报
回复
up

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧