org.apache.jasper.JasperException: Cannot find bean under name myBean

R

rjweytens

I have a web app I am developing using Struts 1.1. I am using Tomcat
4.1.30, and JDK 1.4.2.

The page I am working on (new.jsp) takes several text boxes as input,
plus some selection boxes that are populated from a database when the
page is rendered (ActionForm=RFCActionForm and Action=NewRFCAction).

The page should be validated when the user clicks the submit
button(Action=AddRFCAction). If there are no errors on the page, data
is added to the database and it goes on its merry way. The problem
comes whenever the action needs to go back to new.jsp (all error
messages are displayed at the top of the jsp).

Code samples are below. I posted my actionforms and actions, web.xml
and struts-config.xml. I labeled them as: ***struts-config.xml***.
Please let me know if you need to see any other code.

This is a new, incomplete app, with very simple code. I am not
collecting all information on this form yet, as I am just trying to
get it working.

I have done everything but go out and buy a Struts book (which I am
going to do). I have read several online struts books, searched
forums, searched Struts documentation. I have no peers to ask, I am
alone on this project.

Also, I kindly ask: Please don't say "oh, you just have to do 'this'".
I have come close to finding answers but end at dead ends because
there is no explanation of how to do 'this'.

I'm at my wits end. Please advise.


***new.jsp***

<html>

<head>
<%@ include file='/lib/header.html' %>
</head>

<body>

<h1> Create New RFC </h1>

<html:errors/>

<html:form action="/AddRFC" name="RFCActionForm"
type="rfc.RFCActionForm">
<table border="0" cellspacing="5">
<tr>
<th><b>Business Systems:</b></th>
<th><b>Change Types:</b></th>
<th><b>Locations:</b></th>
</tr>
<tr>
<td>
<html:select property="bs_id" multiple="true">
<html:eek:ptions collection="business_system" property="bs_id"
labelProperty="bs_name"/>
</html:select>
</td>
<td>
<html:select property="ct_id" multiple="true">
<html:eek:ptions collection="change_type" property="ct_id"
labelProperty="ct_name"/>
</html:select>
</td>
<td>
<html:select property="cl_id" multiple="true">
<html:eek:ptions collection="change_location" property="cl_id"
labelProperty="cl_name"/>
</html:select>
</td>
</tr>
</table>

<br>

<table border="0" cellspacing="5">
<tr>
<th>Level of Impact:</th>
</tr>
<tr>
<td>
<html:select property="loi_id">
<html:eek:ptions collection="loi" property="loi_id"
labelProperty="loi_name"/>
</html:select>
</td>
</tr>
</table>

<br>

<table border="0" cellspacing="5">
<tr>
<th>Change Description</th>
</tr>
<tr>
<td><html:textarea cols="100" rows="8"
property="chg_desc"></html:textarea></td>
</tr>
<tr>
<th>Impact on Customer</th>
</tr>
<tr>
<td><html:textarea cols="100" rows="8"
property="chg_impact"></html:textarea></td>
</tr>
<tr>
<th>Testing Plan</th>
</tr>
<tr>
<td><html:textarea cols="100" rows="8"
property="chg_plan"></html:textarea></td>
</tr>
<tr>
<th>Backout Plan</th>
</tr>
<tr>
<td><html:textarea cols="100" rows="8"
property="chg_backout"></html:textarea></td>
</tr>
</table>

<br>

<!-- time tags go here -->

<br><br>

<table border="0" cellspacing="5">
<tr>
<td><html:submit/></td>
<td><html:cancel /></td>
<td><html:reset /></td>
</tr>
</table>
</html:form>

</body>

</html>


***struts-config.xml***

<?xml version="1.0" encoding="ISO-8859-1" ?>

<!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>

<!-- data sources must be the first item in the config file -->
<data-sources>

<data-source
type="org.apache.commons.dbcp.BasicDataSource">
<set-property property="driverClassName"
value="com.mysql.jdbc.Driver" />
<set-property property="url"
value="jdbc:mysql://localhost/rfc3" />
<set-property property="username"
value="" />
<set-property property="password"
value="" />
</data-source>

</data-sources>

<!-- tie actions to JavaBeans -->
<form-beans>

<form-bean name="RFCActionForm"
type="rfc.RFCActionForm" />

</form-beans>

<!-- define actions -->
<action-mappings>

<action path="/New"
type="rfc.NewRFCAction"
scope="request">
<forward name="success" path="/new.jsp"/>
<forward name="error" path="/index.jsp"/>
</action>

<action path="/AddRFC"
type="rfc.AddRFCAction"
name="RFCActionForm"
scope="request"
input="/new.jsp"
validate="true">
<forward name="success" path="/index.jsp"/>
<forward name="error" path="/new.jsp"/>
</action>

</action-mappings>

<!-- define names that can be used with struts html:link tags for
the whole app -->
<global-forwards>
<forward name="home" path="/index.jsp"/>
</global-forwards>

</struts-config>

***web.xml***

<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>

<display-name>RFC</display-name>
<description>
Request for Change
</description>

<!--log4j servlet -->
<servlet>
<servlet-name>log4Jinit</servlet-name>
<servlet-class>rfc.Log4jInitServlet</servlet-class>
<init-param>
<param-name>properties</param-name>
<param-value>WEB-INF/classes/log4j.properties</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>application</param-name>
<param-value>ApplicationResources</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>

<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>

<taglib>
<taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-html.tld</taglib-location>
</taglib>

<taglib>
<taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
</taglib>

<security-constraint>
<display-name>RFC Security Constraint - Entire
Application</display-name>
<web-resource-collection>
<web-resource-name>Application</web-resource-name>
<url-pattern>/index.jsp</url-pattern>
<!--
<url-pattern>index.do</url-pattern>
-->
</web-resource-collection>
<auth-constraint>
<role-name>guest</role-name>
<role-name>rfc_app</role-name>
<role-name>rfc_dir</role-name>
<role-name>rfc_coord</role-name>
</auth-constraint>
</security-constraint>

<security-constraint>
<display-name>RFC Security Constraint - New</display-name>
<web-resource-collection>
<web-resource-name>New</web-resource-name>
<url-pattern>/new.jsp</url-pattern>
<!--
<url-pattern>/new.do</url-pattern>
-->
</web-resource-collection>
<auth-constraint>
<role-name>rfc_app</role-name>
<role-name>rfc_dir</role-name>
<role-name>rfc_coord</role-name>
</auth-constraint>
</security-constraint>

<!-- Login configuration uses form-based authentication -->
<login-config>
<auth-method>FORM</auth-method>
<realm-name>RFC Configuration Form-Based Authentication
Area</realm-name>
<form-login-config>
<form-login-page>/login.jsp</form-login-page>
<form-error-page>/notAuthenticated.jsp</form-error-page>
</form-login-config>
</login-config>

<!-- Security roles referenced by this web application -->
<security-role>
<description>
RFC Guest
</description>
<role-name>guest</role-name>
</security-role>

<security-role>
<description>
RFC Change Management Approver Role
</description>
<role-name>rfc_app</role-name>
</security-role>

<security-role>
<description>
RFC Change Management Coordinator Role
</description>
<role-name>rfc_coord</role-name>
</security-role>

<security-role>
<description>
RFC Change Management Director Role
</description>
<role-name>rfc_dir</role-name>
</security-role>


</web-app>


***RFCActionForm.java***

package rfc;

import javax.servlet.http.HttpServletRequest;

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

import org.apache.log4j.Logger;

public class RFCActionForm extends ActionForm {

protected String[] bs_id;
protected String[] ct_id;
protected String[] cl_id;
protected String loi_id;
protected String chg_desc;
protected String chg_impact;
protected String chg_plan;
protected String chg_backout;

public void setBs_id(String[] bs_id) {
this.bs_id = bs_id;
}

public String[] getBs_id() {

return bs_id;
}


public void setCt_id(String[] ct_id) {
this.ct_id = ct_id;
}

public String[] getCt_id() {

return ct_id;
}


public void setCl_id(String[] cl_id) {
this.cl_id = cl_id;
}

public String[] getCl_id() {

return cl_id;
}


public void setLoi_id(String loi_id) {

this.loi_id = loi_id;
}

public String getLoi_id() {

return loi_id;
}


public void setChg_desc(String chg_desc) {

this.chg_desc = chg_desc;
}

public String getChg_desc() {

return chg_desc;
}


public void setChg_impact(String chg_impact) {

this.chg_impact = chg_impact;
}

public String getChg_impact() {

return chg_impact;
}


public void setChg_plan(String chg_plan) {

this.chg_plan = chg_plan;
}

public String getChg_plan() {

return chg_plan;
}


public void setChg_backout(String chg_backout) {

this.chg_backout = chg_backout;
}

public String getChg_backout() {

return chg_backout;
}


// This method is called with every request. It resets the
// Form attribute prior to setting the values in the new
// request.
public void reset(ActionMapping mapping,
HttpServletRequest request) {

if (bs_id != null) {
for (int i=0; i < bs_id.length; i++)
this.bs_id="";
}

if (ct_id != null) {
for (int i=0; i < ct_id.length; i++)
this.ct_id="";
}

if (cl_id != null) {
for (int i=0; i < cl_id.length; i++)
this.cl_id="";
}

this.loi_id = "";
this.chg_desc = "";
this.chg_impact = "";
this.chg_plan = "";
this.chg_backout = "";
}

public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {

Logger logger = Logger.getLogger("rfc.pattern");

ActionErrors errors = new ActionErrors();

if (bs_id == null) {
errors.add("bs_id",
new ActionError("errors.bs_id.required"));
} else {

for (int i=0; i < bs_id.length; i++) {
logger.debug("bs_id: " + bs_id);
}

}


//try {
// if (bs_id.length == 0) {
// errors.add("bs_id",
// new ActionError("errors.bs_id.required"));
// }
//}
//catch (NullPointerException e) {
// errors.add("bs_id",
// new ActionError("errors.bs_id.required"));
// }


//if (ct_id[0] == null) {

// errors.add("ct_id",
// new ActionError("errors.ct_id.required"));
//}
//if (cl_id[0] == null) {

// errors.add("cl_id",
// new ActionError("errors.cl_id.required"));
//}
if ( (loi_id == null) || (loi_id.length() == 0) ) {

errors.add("loi_id",
new ActionError("errors.loi_id.required"));
}
if ( (chg_desc == null) || (chg_desc.length() == 0) ) {

errors.add("chg_desc",
new ActionError("errors.chg_desc.required"));
}
if ( (chg_impact == null) || (chg_impact.length() == 0) ) {

errors.add("chg_impact",
new ActionError("errors.chg_impact.required"));
}
if ( (chg_plan == null) || (chg_plan.length() == 0) ) {

errors.add("chg_plan",
new ActionError("errors.chg_plan.required"));
}
if ( (chg_backout == null) || (chg_backout.length() == 0) ) {

errors.add("chg_backout",
new ActionError("errors.chg_backout.required"));
}

return errors;
}
}


***NewRFCAction.java***

package rfc;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import java.util.ArrayList;

public class NewRFCAction extends Action {

public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {

// Default target to success
String target = new String("success");

ArrayList business_systems = null;
ArrayList change_types = null;
ArrayList change_locations = null;
ArrayList lois = null;

business_systems =
Business_SystemData.getAll(getDataSource(request));
change_types =
Change_TypeData.getAll(getDataSource(request));
change_locations =
Change_LocationData.getAll(getDataSource(request));
lois =
LoiData.getAll(getDataSource(request));

request.setAttribute("business_system", business_systems);
request.setAttribute("change_type", change_types);
request.setAttribute("change_location", change_locations);
request.setAttribute("loi", lois);

// Forward to the appropriate View
return (mapping.findForward(target));
}
}


***AddRFCAction.java***

package rfc;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

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

import org.apache.log4j.Logger;

public class AddRFCAction extends Action {
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {

Logger logger = Logger.getLogger("rfc.pattern");

// Default target to success
String target = new String("success");

if ( isCancelled(request) ) {

// Cancel pressed back to new rfc
return (mapping.findForward("success"));
}

try {

Change change = new Change();
RFCActionForm RFCForm = (RFCActionForm) form;

change.setChg_desc(RFCForm.getChg_desc());
change.setChg_impact(RFCForm.getChg_impact());
change.setChg_plan(RFCForm.getChg_plan());
change.setChg_backout(RFCForm.getChg_backout());

//change.setDepid(new Integer(employeeForm.getDepid()));
//set other crap here

ChangeData.addRFC(change,
getDataSource(request));
}
catch ( Exception e ) {

logger.error("Setting target to error");
target = new String("error");
ActionErrors errors = new ActionErrors();

errors.add(ActionErrors.GLOBAL_ERROR,
new ActionError("errors.database.error",
e.getMessage()));

// Report any errors
if ( !errors.isEmpty() ) {

saveErrors(request, errors);
}
}
// Forward to the appropriate View
return (mapping.findForward(target));
}
}
 
R

rjweytens

I have a web app I am developing using Struts 1.1. I am using Tomcat
4.1.30, and JDK 1.4.2.

The page I am working on (new.jsp) takes several text boxes as input,
plus some selection boxes that are populated from a database when the
page is rendered (ActionForm=RFCActionForm and Action=NewRFCAction).

The page should be validated when the user clicks the submit
button(Action=AddRFCAction). If there are no errors on the page, data
is added to the database and it goes on its merry way. The problem
comes whenever the action needs to go back to new.jsp (all error
messages are displayed at the top of the jsp).

Code samples are below. I posted my actionforms and actions, web.xml
and struts-config.xml. I labeled them as: ***struts-config.xml***.
Please let me know if you need to see any other code.

This is a new, incomplete app, with very simple code. I am not
collecting all information on this form yet, as I am just trying to
get it working.

I have done everything but go out and buy a Struts book (which I am
going to do). I have read several online struts books, searched
forums, searched Struts documentation. I have no peers to ask, I am
alone on this project.

Also, I kindly ask: Please don't say "oh, you just have to do 'this'".
I have come close to finding answers but end at dead ends because
there is no explanation of how to do 'this'.

I'm at my wits end. Please advise.


Maybe this needs clarification. The problem I am having is that when
I click the submit button, my error-validation logic runs (i verified
this by logging messages so I know that this code is running fine) and
if errors are found and the action needs to route me back to the same
page to display the error messages, the following exception is thrown:

Re: org.apache.jasper.JasperException: Cannot find bean under name
business_systems.

Thanks in advance,

Randy
 
R

rjweytens

Thanks to Sudsy for pointing me in the right direction! All that I
needed to do was to put the attributes in session scope:

request.getSession().setAttribute("business_system", business_system);
etc...

And make sure the actions in my struts-config were in session scope.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top