cannot find bean in any scope error

R

raj

I have a small sample application which has 2 jsps and an action form
an action class and the config files. In the input jsp page which is
"Register.jsp" I have fields for first name, last name and alias. In
the output jsp which is "thankyou.jsp" I'm printing the firstname(using
bean:write) taken as input from "register.jsp"
I'm getting the error:
"Error 500: Cannot find bean registrationFormBean in any scope"

My files:

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>

<!-- Data Sources -->
<data-sources>
</data-sources>

<!-- Form Beans -->
<form-beans>
<form-bean name="registrationFormBean"
type="com.webagesolutions.struts.forms.RegistrationFormBean">
</form-bean>
</form-beans>

<!-- Global Exceptions -->
<global-exceptions>
</global-exceptions>

<!-- Global Forwards -->
<global-forwards>
</global-forwards>

<!-- Action Mappings -->
<action-mappings>
<action name="registrationFormBean" path="/register" scope="request"
type="com.webagesolutions.struts.actions.Register"
input="register.jsp">
<forward name="success" path="/thankyou.jsp" redirect="true">
</forward>
<forward name="failure" redirect="false" path="/register.jsp">
</forward>
</action>
</action-mappings>

<!-- Message Resources -->
<message-resources
parameter="com.webagesolutions.struts.resources.ApplicationResources"/>

</struts-config>



register.jsp


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<html:html>
<HEAD>
<%@ page
language="java"
contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"
%>
<META http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1">
<META name="GENERATOR" content="IBM WebSphere Studio">
<META http-equiv="Content-Style-Type" content="text/css">
<LINK href="theme/Master.css" rel="stylesheet"
type="text/css">
<TITLE></TITLE>
</HEAD>

<BODY>
<html:form action="/register.do">
<table align="center">
<tr>
<td>
First Name:</td>
<td>
<html:text property="fname"></html:text></td>
</tr>
<tr>
<td>
Last Name:</td>
<td><html:text property="lname"></html:text></td>
</tr>
<tr>
<td>Alias:</td>
<td><html:text property="alias"></html:text></td>
</tr>
<tr>
<td><html:submit>Submit</html:submit></td>
<td><html:reset>Reset</html:reset></td>
</tr>
</table>
</html:form>


</BODY>
</html:html>

thankyou.jsp


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<html:html>
<HEAD>
<%@ page
language="java"
contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"
%>
<META http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1">
<META name="GENERATOR" content="IBM WebSphere Studio">
<META http-equiv="Content-Style-Type" content="text/css">
<LINK href="theme/Master.css" rel="stylesheet"
type="text/css">
<TITLE></TITLE>
</HEAD>

<BODY>
Thank You!

<bean:write name="registrationFormBean" property="fname"/>

</BODY>
</html:html>


RegistrationFormBean.java

package com.webagesolutions.struts.forms;

import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

/**
* Form bean for a Struts application.
* @version 1.0
* @author
*/
public class RegistrationFormBean extends ActionForm {

private String lname = null;
private String fname = null;
private String alias = null;

/**
* Get lname
* @return String
*/
public String getLname() {
return lname;
}

/**
* Set lname
* @param <code>String</code>
*/
public void setLname(String a) {
this.lname = a;
}

/**
* Get fname
* @return String
*/
public String getFname() {
return fname;
}

/**
* Set fname
* @param <code>String</code>
*/
public void setFname(String n) {
this.fname = n;
}

/**
* Get alias
* @return String
*/
public String getAlias() {
return alias;
}

/**
* Set alias
* @param <code>String</code>
*/
public void setAlias(String c) {
this.alias = c;
}

public void reset(ActionMapping mapping, HttpServletRequest request) {

// Reset values are provided as samples only. Change as appropriate.

fname = "";
lname = "";
alias = "";

}

public ActionErrors validate(
ActionMapping mapping,
HttpServletRequest request) {

ActionErrors errors = new ActionErrors();
// Validate the fields in your form, adding
// adding each error to this.errors as found, e.g.

// if ((field == null) || (field.length() == 0)) {
// errors.add("field", new
org.apache.struts.action.ActionError("error.field.required"));
// }
return errors;

}
}


Register.java
package com.webagesolutions.struts.actions;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
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.webagesolutions.struts.forms.RegistrationFormBean;

/**
* @version 1.0
* @author
*/
public class Register extends Action {

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

ActionErrors errors = new ActionErrors();
ActionForward forward = new ActionForward();
RegistrationFormBean reg = (RegistrationFormBean) form;
try{
//if (!errors.empty()) {
// saveErrors(request, errors);
System.out.println("success");
forward = mapping.findForward("success");
}
catch(Exception e){
forward = mapping.findForward("failure");
}
return (forward);
}

}

can someone help me with this error?
 
W

Wendy Smoak

raj said:
I have a small sample application which has 2 jsps and an action form
an action class and the config files. In the input jsp page which is
"Register.jsp" I have fields for first name, last name and alias. In
the output jsp which is "thankyou.jsp" I'm printing the firstname(using
bean:write) taken as input from "register.jsp"
I'm getting the error:
"Error 500: Cannot find bean registrationFormBean in any scope"

Your form is in request scope. You are redirecting to thankyou.jsp, which
means the browser will make a new request-- and the form bean won't be in
it.

You could put your form in session scope or forward (instead of redirecting)
to thankyou.jsp.
 
A

Aleksander =?iso-8859-2?Q?Str=B1czek?=

raj said:
I have a small sample application which has 2 jsps and an action form
an action class and the config files. In the input jsp page which is
"Register.jsp" I have fields for first name, last name and alias. In
the output jsp which is "thankyou.jsp" I'm printing the firstname(using
bean:write) taken as input from "register.jsp"
I'm getting the error:
"Error 500: Cannot find bean registrationFormBean in any scope"

My files:

struts-config.xml [cut]
<action-mappings>
<action name="registrationFormBean" path="/register" scope="request"
type="com.webagesolutions.struts.actions.Register"
input="register.jsp">
<forward name="success" path="/thankyou.jsp" redirect="true">
</forward>

scope="request" in action element and redirect="true" in forward element
are the source of problem.
redir
Use scope="session" or redirect="false".

redirect="true" effect is finish service for request by sending
http://java.sun.com/products/servle...tResponse.html#sendRedirect(java.lang.String)
to client, then new request is created (in new request is no form-bean).
In this case scope for form-bean have to be "session".

redirect="false" is translated to
http://java.sun.com/products/servle...ervletRequest, javax.servlet.ServletResponse)
so there is no new request and form-bean will be in 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,965
Messages
2,570,148
Members
46,710
Latest member
FredricRen

Latest Threads

Top