File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Cannot find bean lookupForm in any scope" Watch "Cannot find bean lookupForm in any scope" New topic

Cannot find bean lookupForm in any scope

kirty nahar

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"%>
<title>Wrox struts Application</title>

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

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

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

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

<form-bean name="LookupForm" type="selectica.LookupForm"/>

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

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()

public void setSymbol(String symbol)

public void reset(ActionMapping mapping, HttpServletRequest request)


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

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

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

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:
subject: Cannot find bean lookupForm in any scope
It's not a secret anymore!