wood burning stoves 2.0*
The moose likes Struts and the fly likes Cannot find bean lookupForm in any scope 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 "Cannot find bean lookupForm in any scope" Watch "Cannot find bean lookupForm in any scope" New topic
Author

Cannot find bean lookupForm in any scope

kirty nahar
Greenhorn

Joined: May 02, 2002
Posts: 11
I have created a simple Struts Application. When I run it I get following exception
org.apache.jasper.JasperException: Cannot find bean lookupForm in any scope

My index.jsp

<%@ page language="java"%>
<%@ taglib uri = "/WEB-INF/struts-html.tld" prefix="html"%>
<html>
<head>
<title>Wrox struts Application</title>
</head>

<body>tertwr
<table width="500" border="0" cellspacing="0" cellpadding="0">
<tr>
<td> </td>
</tr>

<tr>
<td height="68" width="48%">
<div align="left">
<img src="images/new.gif">
</div>
</td>
</tr>
<tr>
<td> </td>
</tr>
</table>
<html:form action="Lookup" name="LookupForm" type="selectica.LookupForm">

<table width="45%" border="0">
<tr>
<td>Symbol;</td>
<td><html:text property="symbol" /></td>
</tr>
<tr>
<td colspan="2" align="center"><html:submit /></td>
</tr>
</table>
</html:form>
</body>
</html>


My 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>
<form-beans>
<form-bean name="LookupForm" type="selectica.LookupForm"/>
</form-beans>

<action-mappings>
<action path="/Lookup" type="selectica.LookupAction" name="LookupForm">
<forward name="success" path="/quote.jsp"/>
<forward name="failure" path="/index.jsp"/>
</action>
</action-mappings>
</struts-config>


My LookupForm.java
package selectica;

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

public class LookupForm extends ActionForm
{
private String symbol=null;

public String getSymbol()
{
return(symbol);

}
public void setSymbol(String symbol)
{
this.symbol=symbol;
}

public void reset(ActionMapping mapping, HttpServletRequest request)
{
this.symbol=null;
}


}


Kindly let me know what could be the possible problem.
Michal Bienek
Greenhorn

Joined: Jun 17, 2002
Posts: 29
It appears that you do not have the LookupForm populated in your request or session prior to your jsp being displayed and by specifying:

you are telling the jsp to populate itself based on a bean that's already expected to exist.
Check if removing the name/type from the html:form tag helps you.
Jonathan Lehr
author
Greenhorn

Joined: Oct 07, 2003
Posts: 20
Hi Kirty,

As Michal correctly points out, the LookupForm isn't in the session when the JSP tag tries to reference it. Here's why.

If you take a look at the "/Lookup" action mapping in your struts-config.xml, you'll see that it includes the following attribute setting: name="LookupForm". This tells Struts to try to find an instance of LookupForm in the configured scope (the default scope being 'session'). If no instance is found, the framework will create one and put it in scope under the key "LookupForm" automatically for you.

If you navigate directly to your example index.jsp after starting up the server, Struts won't have an opportunity to evaluate the action mapping, so the LookupForm won't be created.

To fix this, rename index.jsp (for example, you might want to name it something like 'Lookup.jsp'), and then create a new version of index.jsp that contains a 'Lookup' hyperlink, as in the following example:

When clicked, the hyperlink will trigger the action mapping so that the LookupForm instance will be created and placed in the session before the JSP tries to evaluate the <html:form> tag that refers to the instance.

There's one more thing you'll need to do to make this work. In struts-config.xml, change the 'forward' configuration in the "/Lookup" action mapping to make it forward to the new JSP, as in the following:

kirty nahar
Greenhorn

Joined: May 02, 2002
Posts: 11
Thanks for the response. Now it gives me this error.

org.apache.jasper.JasperException: /index.jsp(25,0) Unable to find setter method for attribute: name
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cannot find bean lookupForm in any scope
 
Similar Threads
DynaActionForm - Exception creating bean
Exception creating bean of class...
Error in deploying struts: Attribute name invalid according to the specified TLD
ActionForm class
JasperException