File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes iam getting problem in <html:OptionsCollection> Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "iam getting problem in <html:OptionsCollection>" Watch "iam getting problem in <html:OptionsCollection>" New topic

iam getting problem in <html:OptionsCollection>

parthiban thrangaraju

Joined: Feb 06, 2011
Posts: 25
iam getting problem in <html:OptionsCollection>

my attachement is here

jsp file:

<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

<%@ taglib uri="" prefix="bean" %>
<%@ taglib uri="" prefix="html" %>
<%@ taglib uri="" prefix="logic" %>

<html lang="en">
<title> <bean:message key="clientscomment.title1"/> </title>

<body id="page6">
<!-- header -->

<div class="inside">
<html:form action="/" styleId="contacts-form">

<div class="col-1">

<bean:message key="clientscomment.title3"/><br/>

<html:text property="name" />
<html:errors property="name"/>
<bean:message key="clientscomment.title8"/>

<html:select property="typeofbusiness" name="ClientsCommentForm" >
<%--<html:select property="typeofbusiness">--%>
<htmlption value="">Select TypeofBusiness</htmlption>
<htmlptionsCollection name="ClientsCommentForm" property="typeofbusinesslist" label="typeofbusinesslist" value="typeofbusinessId" />
<%--<htmlptions collection="typeofbusinesslist" labelProperty="typeofbusinessId" labelName="typeofbusinesslist"/>--%>

<html:errors property="typeofbusiness"/><br/>
<bean:message key="clientscomment.title4"/>

<html:text property="email" />
<html:errors property="email"/>
<bean:message key="clientscomment.title7"/>
<html:text property="contactno" />
<html:errors property="contactno"/>
<bean:message key="clientscomment.title5"/><br/>

<html:text property="state" />
<html:errors property="state"/>
<div class="col-2">
<bean:message key="clientscomment.title6"/><br />
<html:textarea property="message" />
<html:errors property="message"/>

<div class="wrapper">
<html:submit value="SUBMIT" styleId="submit" property="method" />


action form:

package Classes.ClientsComment;

import java.util.ArrayList;

public class ClientsCommentForm extends org.apache.struts.validator.ValidatorForm {

private String name;
private String email;
private String contactno;
private String state;
private String message;
private String typeofbusiness;
private ArrayList typeofbusinesslist;

public String getTypeofbusiness() {
return typeofbusiness;

public String getContactno() {
return contactno;

public String getEmail() {
return email;

public String getMessage() {
return message;

public String getName() {
return name;

public String getState() {
return state;

public ArrayList getTypeofbusinesslist() {
return typeofbusinesslist;

public ClientsCommentForm() {

public void setEmail(String email) { = email;

public void setMessage(String message) {
this.message = message;

public void setName(String name) { = name;

public void setState(String state) {
this.state = state;

public void setContactno(String contactno) {
this.contactno = contactno;

public void setTypeofbusiness(String typeofbusiness) {
this.typeofbusiness = typeofbusiness;

public void setTypeofbusinesslist(ArrayList typeofbusinesslist) {
this.typeofbusinesslist = typeofbusinesslist;


action class:

package Classes.ClientsComment;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class ClientsCommentAction extends org.apache.struts.actions.DispatchAction {

private static final String SUCCESS = "success";
private static final String SUCCESS1 = "success";

public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
ClientsCommentForm ccf=(ClientsCommentForm) form;

String name=ccf.getName();
String email=ccf.getEmail();
String contactno=ccf.getContactno();
String state=ccf.getState();
String message=ccf.getMessage();

String url="jdbc:mysql://localhost:3306/nemogroups";
Connection con=DriverManager.getConnection(url, "root","root");
Statement st=con.createStatement();
String insert="insert into clientcomment(name,email,contactno,state,message)values('"+name+"','"+email+"','"+contactno+"','"+state+"','"+message+"')";

return mapping.findForward(SUCCESS);

public ActionForward populate(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse resonse){

ArrayList typeofbusinesslist=new ArrayList();

ClientsCommentForm ccf1=(ClientsCommentForm) form;

typeofbusinesslist.add(new TypeofBusiness("1", "NemoTravels"));
typeofbusinesslist.add(new TypeofBusiness("2", "NemoHotels"));
typeofbusinesslist.add(new TypeofBusiness("3", "NemoCorporateService"));
typeofbusinesslist.add(new TypeofBusiness("4", "NemoAgriCulture"));
typeofbusinesslist.add(new TypeofBusiness("5", "NemoConstructions"));
typeofbusinesslist.add(new TypeofBusiness("6", "NemoFoundation"));
typeofbusinesslist.add(new TypeofBusiness("7", "NemoItSolutions"));


return mapping.findForward(SUCCESS1);

java class:

* To change this template, choose Tools | Templates
* and open the template in the editor.

* @author Parthibant
public class TypeofBusiness {

private String typeofbusinessId;
private String typeofbusinessName;

public TypeofBusiness(String typeofbusinessId, String typeofbusinessName) {
this.typeofbusinessId = typeofbusinessId;
this.typeofbusinessName = typeofbusinessName;

public String getTypeofbusinessId() {
return typeofbusinessId;

public String getTypeofbusinessName() {
return typeofbusinessName;

public void setTypeofbusinessId(String typeofbusinessId) {
this.typeofbusinessId = typeofbusinessId;

public void setTypeofbusinessName(String typeofbusinessName) {
this.typeofbusinessName = typeofbusinessName;


while executing this program i am getting the following error


javax.servlet.ServletException: javax.servlet.jsp.JspException: Failed to obtain specified collection

root cause

javax.servlet.jsp.JspException: Failed to obtain specified collection

thanks in advance

Raaja Gotluru
Ranch Hand

Joined: Mar 02, 2010
Posts: 118

Just in the populate action method instead of adding the list to form just keep that list in request scope.

in jsp
<logic:notEmpty name="typeofbusinesslist">
<htmlptions collection="typeofbusinesslist" labelProperty="typeofbusinessId" labelName="typeofbusinesslist"/>

notEmpty is used in order to avoid exception if the list is empty.

--raaja. g
parthiban thrangaraju

Joined: Feb 06, 2011
Posts: 25

thanks raaja

now the program is executed and the form is displayed but the problem is, the is list in drop down box is not displaying, its just displaying select the business type alone.

can you help me for this problem.

thanks in advance
parthiban thrangaraju

Joined: Feb 06, 2011
Posts: 25
can any one help me to solve this problem
Guy Belpa
Ranch Hand

Joined: Nov 21, 2004
Posts: 41

Make sure this action forwards to the JSP, and then call the URL for the action (/ rather than calling the JSP directly (/mypage.jsp).
I agree. Here's the link:
subject: iam getting problem in <html:OptionsCollection>
It's not a secret anymore!