File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Help Need Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Help Need " javax .servlet.jsp.Jsp Exception: Failed to obtain specified collection"" Watch "Help Need " javax .servlet.jsp.Jsp Exception: Failed to obtain specified collection"" New topic
Author

Help Need " javax .servlet.jsp.Jsp Exception: Failed to obtain specified collection"

Revanth reddy
Ranch Hand

Joined: Oct 10, 2008
Posts: 52
Hi All,
i am working on a simple struts application. i got struck at one point for the past two days, i am posting my code and stack trace. any help greatly appreciated.


The problem soluton is:
I have a jsp page in that if i click on a link it should show me salesModel in a select box with prepopulated data from db.

Thanks in advance.


Here is my JSP
salesModelLookup.jsp

<%@ page language="java"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested"%>
<html>

<script>

javascript:window.history.forward(1);

function loadOnChangeModel()
{

document.SalesModelForm.action="/SalesModel.do?method=onChangeModel";
document.SalesModelForm.submit();
}

</script>

<body>
<jsp:include page="motoHeader.jsp"/><br/><br/><br/><br/>
<center>
<html:errors/>
<br/><br/><br/>

<font size="5" color='#2B60DE'><h3><u>BOM Look-Up :</u></h3>
</font>
</br></br>
<h4>Please select the sales model</h4>

<br><br>
//<html:form action="/SalesModel.do">
<table>

<tr><td>
<h3>SALES MODEL</h3>
</td><td>
<html:select name="SalesModelForm" property="model" styleId="model" tabindex="8" onchange="loadOnChangeModel()">
<htmlption value="0">SELECT</htmlption>
<htmlptionsCollection label="model" value="modelId" property="salesModelBean" name="SalesModelForm"/>
</html:select>
<br><br>
</td></tr>
</table>
<br/><br/>
<html:submit></html:submit>

</html:form>
<br/><br/>
<input type="button" name="TAC Configuration Menu" value= "TAC Configuration Menu" onKlick="window.location.href='/GFSConfigurationTool/TacCode.do?method=tacList'">
</center>
<br/>
<br/><br/><br/><jsp:include page="motoFooter.jsp"/>
</body>
</html>


Here is my Actionform
SalesModelLookup.java

package com.mot.reports.forms;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

import com.mot.reports.vo.SalesModelBean;
import com.mot.reports.vo.SalesModelLookUpVO;




/**
* MyEclipse Struts
* Creation date: 04-11-2008
*
* XDoclet definition:
* @struts.form name="TacCode"
*/
public class SalesModelForm extends ActionForm {
/*
* Generated Methods
*/

/**
* Method validate
* @param mapping
* @param request
* @return ActionErrors
*/

/**
*
*/
private static final long serialVersionUID = 1L;
/**
*
*/
//private static final long serialVersionUID = 1L;
/**
*
*/

List <SalesModelBean> salesModelBean;
//List <SalesModelLookUpVO> salesModelResults;
String model;
//int salesModelId;


public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
// TODO Auto-generated method stub
return null;
}

/**
* Method reset
* @param mapping
* @param request
*/
public void reset(ActionMapping mapping, HttpServletRequest request) {
// TODO Auto-generated method stub

}


public List<SalesModelBean> getSalesModelBean() {
return salesModelBean;
}

public void setSalesModelBean(List<SalesModelBean> salesModelBean) {
this.salesModelBean = salesModelBean;
}


//public List<SalesModelLookUpVO> getSalesModelResults() {
//return salesModelResults;
//}
//
//public void setSalesModelResults(List<SalesModelLookUpVO> salesModelResults) {
//this.salesModelResults = salesModelResults;
//}

//public int getSalesModelId() {
//return salesModelId;
//}
//
//public void setSalesModelId(int salesModelId) {
//this.salesModelId = salesModelId;
//}

public String getModel() {
return model;
}

public void setModel(String model) {
this.model = model;
}

}

Here is my DAO
SalesModelLookUpDAO.java

package com.mot.reports.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import com.mot.reports.actions.util.Resource;
import com.mot.reports.forms.SalesModelForm;
import com.mot.reports.vo.SalesModelBean;
import com.mot.reports.vo.SalesModelLookUpVO;


public class SalesModelLookUpDAO {
@SuppressWarnings("unchecked")
public static ArrayList ModelLookUp(Connection db)
{

SalesModelBean SMbean = null;

PreparedStatement st = null;
ResultSet rs = null;
ArrayList<SalesModelBean> SMbeans=new ArrayList<SalesModelBean>();

try {

st = db.prepareStatement(salesModelLookUp);
//st.setInt(1, salesModelform.getSalesModelId());
rs = st.executeQuery();
while (rs.next()) {
SMbean=new SalesModelBean();
SMbean.setModelId(rs.getInt("assembly_item_id"));
//SMbean.setModel(rs.getString("model"));

SMbeans.add(SMbean);
}
System.out.println("::::::::::::::::"+SMbean);
// salesModelform.setSalesModelBean(models);

} catch (SQLException e) {

return null;
} finally {
try {
if (st != null) {
st.close();
}
} catch (SQLException e) {
e.printStackTrace();
}

try {
if (rs != null) {
rs.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}

return SMbeans;


}
@SuppressWarnings("unchecked")
public static String SalesModelLookUpBillSequenceId(Connection db)
{

SalesModelLookUpVO salesVO = null;

PreparedStatement st = null;
ResultSet rs = null;

ArrayList<SalesModelLookUpVO> salesModelVOList=new ArrayList<SalesModelLookUpVO>();


try {

st = db.prepareStatement(salesModelLookUpBillSequenceId);
rs = st.executeQuery();


while (rs.next()) {
salesVO=new SalesModelLookUpVO();
salesVO.setBillSequenceId(rs.getString("bill_sequence_id"));
System.out.println("Bill Sequence Id"+ salesVO);
}

} catch (SQLException e) {

return null;
} finally {
try {
if (st != null) {
st.close();
}
} catch (SQLException e) {
e.printStackTrace();
}

try {
if (rs != null) {
rs.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}

return salesVO.getBillSequenceId();

}

@SuppressWarnings("unchecked")
public static ArrayList SalesModelLookUpResults(Connection db,String model)
{

SalesModelLookUpVO salesVO = null;

PreparedStatement st = null;
ResultSet rs = null;
String sql=null;
ArrayList<SalesModelLookUpVO> salesModelVOList=new ArrayList<SalesModelLookUpVO>();


try {

st = db.prepareStatement(salesModelLookUpResults);
st.setString(1, model);
rs = st.executeQuery();
int count=0;
while (rs.next()) {
salesVO=new SalesModelLookUpVO();
salesVO.setBillSequenceId(rs.getString("bill_sequence_id"));
salesVO.setPart(rs.getString("part"));
salesVO.setItemTypeCode(rs.getString("ITEM_TYPE_CODE"));
salesVO.setItemid(rs.getInt("ITEM_ID"));
salesVO.setItemNumber(rs.getInt("ITEM_NUMBER"));
salesVO.setPartDescription(rs.getString("DESCRIPTION"));
salesVO.setStatusCode(rs.getInt("INVENTORY_STATUS_CODE"));
salesVO.setEffectiveDate(Resource.dateString(rs.getDate("EFFECTIVITY_DATE")));
salesVO.setDisableDate(Resource.dateString(rs.getDate("DISABLE_DATE")));
salesVO.setOrganizationCode(rs.getString("ORGANIZATION_CODE"));
salesModelVOList.add(salesVO);
count++;

}

} catch (SQLException e) {

return null;
} finally {
try {
if (st != null) {
st.close();
}
} catch (SQLException e) {
e.printStackTrace();
}

try {
if (rs != null) {
rs.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}

return salesModelVOList;

}
private static final String salesModelLookUpBillSequenceId = "SELECT"+
"wbom.bill_sequence_idFROM"+
"wo_bill_of_materials wbom,"+
"wo_items wi"+
"WHERE" +
"wi.item_number = '&Salesmodel' " +
"AND wbom.assembly_item_id = wi.item_id ";

private static final String salesModelLookUpResults = " SELECT* FROM" +
"(SELECT DISTINCT " +
" DECODE(wit.ITEM_TYPE_CODE, 'MO', 'Model', 'TR', 'Xcvr', 'SO', 'Software', 'AC', 'Accy') Part,"+
"wit.ITEM_TYPE_CODE itc,"+
"wi.ITEM_ID, " +
"wi.ITEM_NUMBER," +
"wi.DESCRIPTION, " +
"wi.INVENTORY_STATUS_CODE status, " +
"' ' 'Eff Date', " +
"' ' 'Disable Date', " +
" woo.organization_code 'Org' " +
"FROM wo_items wi, " +
"wo_item_types wit, " +
"wo_bill_of_materials wbom, " +
"wo_organizations woo " +
"WHERE wi.ITEM_NUMBER = '&&SalesModel' " +
"AND wi.ITEM_TYPE_ID = wit.ITEM_TYPE_ID " +
"AND wbom.assembly_item_id = wi.ITEM_ID " +
"AND wi.ORGANIZATION_ID = woo.ORGANIZATION_ID " +
"UNION SELECT DISTINCT " +
"DECODE(wit.item_type_code, 'MO', 'Model', 'TR', 'Xcvr', 'SO', 'Software', 'AC', 'Accy') Part, " +
"wit.item_type_code itc, " +
"wi.ITEM_ID, " +
"wi.ITEM_NUMBER, " +
"wi.DESCRIPTION, " +
"wi.INVENTORY_STATUS_CODE status, " +
"to_char(wic.EFFECTIVITY_DATE, 'MM/DD/RR HH24:MI:SS') 'Eff Date', " +
"to_char(wic.DISABLE_DATE, 'MM/DD/RR HH24:MI:SS') 'Disable Date', " +
"woo.organization_code 'Org' " +
"FROM wo_bill_of_materials wbom, " +
"wo_inventory_components wic, " +
"wo_items wi, " +
"wo_item_types wit, " +
"wo_organizations woo " +
"WHERE wbom.bill_sequence_id = wic.bill_sequence_id " +
"AND wi.ITEM_ID = wic.component_ITEM_ID " +
"AND wi.ORGANIZATION_ID = woo.ORGANIZATION_ID " +
"AND wi.ITEM_TYPE_ID = wit.ITEM_TYPE_ID " +
"AND wic.EFFECTIVITY_DATE < SYSDATE " +
"AND (wic.DISABLE_DATE is NULL or wic.DISABLE_DATE > SYSDATE) " +
"AND wbom.assembly_item_id = ( SELECT DISTINCT " +
" assembly_item_id " +
"FROM wo_bill_of_materials wbom1, wo_items wi1 " +
"WHERE wi1.ITEM_NUMBER='&&SalesModel' " +
"AND wi1.ITEM_ID = wbom1.assembly_item_id ) " +
"UNION --Pick up the substitute components " +
"SELECT DISTINCT " +
"DECODE(wit.item_type_code, 'MO', 'Model', 'TR', 'Xcvr', 'SO', 'Software', 'AC', 'Accy') Part, " +
"wit.item_type_code itc, " +
"wi.ITEM_ID, " +
"wi.ITEM_NUMBER, " +
"'** (Substitute for item: '||wi2.ITEM_ID||') '||wi.DESCRIPTION, " +
"wi.INVENTORY_STATUS_CODE status, " +
"to_char(wic.EFFECTIVITY_DATE, 'MM/DD/RR HH24:MI:SS') 'Eff Date', " +
"to_char(wic.DISABLE_DATE, 'MM/DD/RR HH24:MI:SS') 'Disable Date', " +
"woo.organization_code 'Org' " +
"FROM wo_bill_of_materials wbom, " +
"wo_inventory_components wic, " +
"wo_items wi, " +
"wo_items wi2, " +
"wo_item_types wit, " +
"wo_substitute_components wsc, " +
"wo_organizations woo " +
"WHERE wbom.bill_sequence_id = wic.bill_sequence_id " +
"AND wsc.component_sequence_id = wic.component_sequence_id" +
"AND wi.ITEM_ID = wsc.substitute_ITEM_ID " +
"AND wi2.ITEM_ID = wic.component_ITEM_ID " +
"AND wi.ORGANIZATION_ID = woo.ORGANIZATION_ID " +
"AND wi.ITEM_TYPE_ID = wit.ITEM_TYPE_ID " +
"AND wic.EFFECTIVITY_DATE < SYSDATE " +
"AND(wic.DISABLE_DATE is NULL or wic.DISABLE_DATE > SYSDATE) " +
"AND wbom.assembly_item_id =( SELECT DISTINCT " +
"assembly_item_id " +
"FROM wo_bill_of_materials wbom1, " +
"wo_items wi1 " +
"WHERE wi1.ITEM_NUMBER = '&&SalesModel' " +
"AND wi1.ITEM_ID = wbom1.assembly_item_id " +
"ORDER BY DECODE(itc, 'MO', 'A', 'TR', 'B', 'SO', 'C', 'AC', 'D', 'E') ASC, 3 ASC" ;

private static final String salesModelLookUp ="SELECT" +
"wbom.assembly_item_id" +
"FROM wo_bill_of_materials wbom,"+
"wo_items wi"+
"WHERE"+
"wbom.assembly_item_id=wi.item_id"+
"AND wi.item_type_id ='0'";



}

Finally here is my Action:

SalesModelAction.java

package com.mot.reports.actions;

import java.sql.Connection;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.mot.reports.dao.SalesModelLookUpDAO;
import com.mot.reports.forms.SalesModelForm;

import com.mot.reports.DBConnection.Database;
import com.mot.reports.actions.BaseAction;


public class SalesModelAction extends BaseAction {

public ActionForward onChangeModel(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {

SalesModelForm SalesModelform = (SalesModelForm) form;// TODO Auto-generated method stub

Database database=new Database();
Connection db=database.getDatabaseConnection();
HttpSession session=request.getSession();
//session.setAttribute(SalesModelform, arg1)
if(SalesModelform.getModel()==null )
{
session.removeAttribute("SalesModelForm");
return mapping.findForward("reSet");
}
session.setAttribute("SalesModelform", SalesModelform);
SalesModelform.setSalesModelBean(SalesModelLookUpDAO.ModelLookUp(db));
//SalesModelform.setSalesModelBean(SalesModelLookUpDAO.ModelLookUp(db));
return mapping.findForward("success");
}

public ActionForward reset(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {

HttpSession session=request.getSession();

session.removeAttribute("SalesModelForm");
return mapping.findForward("reSet");

}

public ActionForward mainConfiguraion(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {

HttpSession session=request.getSession();
session.removeAttribute("SalesModelForm");
return mapping.findForward("mainConfig");
}
}



StrutsConfig.xml::

<action

attribute="SalesModelForm"
name="SalesModelForm"
path="/SalesModel"
parameter="method"
scope="session"

type="com.mot.reports.actions.SalesModelAction" >
<forward name="success" path="/jsp/salesModelLookUp.jsp"/>
<forward name="failure" path="/jsp/reportsList.jsp"/>
<forward name="mainConfig" path="/jsp/menu.jsp"/>
<forward name="reSet" path="/TacCode.do?method=Handle"/>

</action>

getting the fallowing exception:::


SEVERE: Servlet.service() for servlet jsp threw exception
javax.servlet.jsp.JspException: Failed to obtain specified collection
at org.apache.struts.taglib.html.OptionsCollectionTag.doStartTag(OptionsCollectionTag.java:176)
at org.apache.jsp.jsp.salesModelLookUp_jsp._jspx_meth_html_optionsCollection_0(salesModelLookUp_jsp.java:288)
at org.apache.jsp.jsp.salesModelLookUp_jsp._jspx_meth_html_select_0(salesModelLookUp_jsp.java:222)
at org.apache.jsp.jsp.salesModelLookUp_jsp._jspx_meth_html_form_0(salesModelLookUp_jsp.java:171)
at org.apache.jsp.jsp.salesModelLookUp_jsp._jspService(salesModelLookUp_jsp.java:112)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:541)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:619)


Please help me..Please......
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61611
    
  67

Please be sure to use UBB code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please read this for more information.

You can go back and change your post to add code tags by clicking the .

Also, please post Struts questions in the Struts forum. I have moved this post there for you.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Tom Rispoli
Ranch Hand

Joined: Aug 29, 2008
Posts: 349
Struts may require an indexed getter method for salesModelBean. Adding that to your form may allow the optionsCollection tag to work correctly.
Revanth reddy
Ranch Hand

Joined: Oct 10, 2008
Posts: 52
Problem solved !!!
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 (/myaction.do) rather than calling the JSP directly (/mypage.jsp).
 
Don't get me started about those stupid light bulbs.
 
subject: Help Need " javax .servlet.jsp.Jsp Exception: Failed to obtain specified collection"