This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Struts and the fly likes javax.servlet.jsp.JspException: Cannot find bean under name jobtitleList Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "javax.servlet.jsp.JspException: Cannot find bean under name jobtitleList" Watch "javax.servlet.jsp.JspException: Cannot find bean under name jobtitleList" New topic
Author

javax.servlet.jsp.JspException: Cannot find bean under name jobtitleList

debanjana chakraborty
Greenhorn

Joined: Mar 08, 2010
Posts: 3
i have an struts error and stuck with it. I am sending the whole program.
index.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="/WEB-INF/app.tld" prefix="app"%>
<%@ 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"%>
<%@ page import="java.util.*" %>
<%List list=(List)request.getAttribute("jobtitleList");
//System.out.println(list.get(0));
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html:html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<link href="css/style.css" rel="stylesheet" type="text/css">
<title>search page</title>
</head>
<body bgcolor="F5E4C7" leftmargin="0" topmargin="0" marginwidth="0"
marginheight="0" onLoad="cursor();">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="0A50A1"><img src="images/title.gif" width="376"
height="59"></td>
</tr>
<tr>
<td valign="top" class="bodyTextBold"><img
src="images/spacer.gif" width="17"><br>
<html:form action="/searchGo">
<table cellspacing=0 cellpadding=0 width=250 border=0>
<tbody>
<tr>
<td rowspan="3"><img src="images/spacer.gif" width="19"></td>
<td width=11><img height=11
src="images/rounded_box_r1_c1.gif" width=11></td>
<td width=235 background="images/rounded_box_r1_c2.gif"><img
src="images/transparent.gif" width="1" height="1"></td>
<td width=11><img height=11
src="images/rounded_box_r1_c4.gif" width=11></td>
</tr>
<tr>
<td class=text background="images/rounded_box_r2_c1.gif"> </td>
<td valign="top" class=bodyText>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="3"><img src="images/label.gif" width="300"
height="50"></td>
</tr>
<tr>
<td colspan="3"><img src="images/small-label.gif"></td>
</tr>
<tr class="bodyTextBold">
<td align="right" nowrap><bean:message key="prompt.jobtitle" /></td>
<td nowrap> </td>
<td nowrap><html:select styleClass="bodyText" property="jobtitles" multiple="true" size="5">
<htmlption value="0">Select jobtitle</htmlption>
<htmlptions collection="jobtitleList" property="value" labelProperty="label"/>
</html:select></td>
</tr>
</table>
</td>
<td background="images/rounded_box_r2_c5.gif"> </td>
</tr>
<tr>
<td valign="top"><img height=11
src="images/rounded_box_r4_c1.gif" width=11></td>
<td align=right background="images/rounded_box_r4_c2.gif"
class="SMALL"> </td>
<td valign="top"><img height=11
src="images/rounded_box_r4_c4.gif" width=11></td>
</tr>
</tbody>
</table>
</html:form></td>
</tr>
</table>
</body>
</html:html>

SearchForm.java(formbean)
package employeelocator.domain;

import org.apache.struts.action.ActionForm;

import com.ConnectionFactory;

public class SearchForm extends ActionForm {
private String[] jobtitles = null;

public String[] getJobtitles() {
return jobtitles;
}

public void setJobtitles(String[] jobtitles) {
this.jobtitles = jobtitles;
}

}

SearchAction that extends BaseAction(My action class)

BaseAction.java
package employeelocator.action;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.util.LabelValueBean;

import com.ConnectionFactory;

public class BaseAction extends Action {
public static void setEmployeeDropDownList(HttpServletRequest request) {
// get new modifiable data List
List<LabelValueBean> jobtitlelist = new ArrayList<LabelValueBean>();
String query1 = "select jobtitle from my_employeeloc";

try {
Connection conn = null;
ResultSet rs = null;
Statement st = null;
conn = ConnectionFactory.getConnection();
st = conn.createStatement();
st.executeQuery(query1);
rs = st.getResultSet();
System.out.println("Before rs");
while (rs.next()) {
System.out.println("Before label Value Bean");
LabelValueBean lvb1 = new LabelValueBean(rs
.getString("jobtitle"), rs.getString("jobtitle"));
jobtitlelist.add(lvb1);
}

} catch (Exception ee) {
ee.printStackTrace();
}
request.setAttribute("jobtitleList", jobtitlelist);

}
}
SearchAction.java

package employeelocator.action;

import java.io.IOException;
import java.util.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.*;

import employeelocator.domain.SearchForm;

public class SearchAction extends BaseAction {
@Override
public ActionForward perform(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
String[] jobtitles = null;

// get parameters
jobtitles = (String[]) request.getAttribute("jobtitleList");
SearchForm dataform = (SearchForm) form;
dataform.setJobtitles(jobtitles);
return (mapping.findForward("search"));

}
}
Prashant Langade
Ranch Hand

Joined: Jul 01, 2009
Posts: 71
Hi

It would be good if you would had placed your code int code tags

Its really difficult to understand the problem.

Prashant
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: javax.servlet.jsp.JspException: Cannot find bean under name jobtitleList
 
Similar Threads
Expression Language not supported in compile time attribute items
tiles and <sx:autocompleter>
When Validation Error I Lose My Bean Value-Struts 2
jsp:include and c:import combination/nesting
The method print(boolean) in the type JspWriter is not applicable for the arguments(void)