• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Cannot find bean lookupForm in any scope

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic