New to Struts
I am getting the following error and I am stuck..
ERROR
message /index.jsp (line: 28, column: 4) Unable to find setter method for attribute: name
description The server encountered an internal error (/index.jsp (line: 28, column: 4) Unable to find setter method for attribute: name) that prevented it from fulfilling this request.
My understanding
Line 28 is <html:form action="Lookup" name="lookupForm" type="ch03.LookupForm" >
name on the index page represents the javabean data
type = the qualified path and name of the javabean
index.jsp
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<html>
<head>
<title>Wrox Struts Application</title>
</head>
<body>
<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/wxmainlogowhitespace.gif">
</div>
</td>
</tr>
<tr>
<td> </td>
</tr>
</table>
<html:errors />
<html:form action="Lookup"
name="lookupForm"
type="ch03.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>
JavaBean
package ch03;
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;
}
}
Controller
package ch03;
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;
public class LookupAction extends Action {
protected Double getQuote(String symbol) {
if ( symbol.equalsIgnoreCase("SUNW") ) {
return new Double(25.00);
}
return null;
}
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
Double price = null;
// Default target to success
String target = new String("success");
if ( form != null ) {
LookupForm lookupForm = (LookupForm)form;
String symbol = lookupForm.getSymbol();
price = getQuote(symbol);
}
// if price is null, set the target to failure
if ( price == null ) {
target = new String("failure");
}
else {
request.setAttribute("PRICE", price);
}
// Forward to the appropriate View
return (mapping.findForward(target));
}
}
struts-config.xml
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
"
<struts-config>
<form-beans>
<form-bean name="lookupForm"
type="ch03.LookupForm"/>
</form-beans>
<action-mappings>
<action path="/Lookup"
type="ch03.LookupAction"
name="lookupForm" >
<forward name="success" path="/quote.jsp"/>
<forward name="failure" path="/index.jsp"/>
</action>
</action-mappings>
</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"
"
<web-app>
<!-- Standard ActionServlet Configuration -->
<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>
<!-- Standard ActionServlet Mapping -->
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<!-- Standard Welcome File List -->
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<!-- Struts Tag Library Descriptors -->
<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>
</web-app>
quote.jsp
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<html>
<head>
<title>Wrox Struts Application</title>
</head>
<body>
<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/wxmainlogowhitespace.gif">
</div>
</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>
<bean:message key="app.price" />: <%= request.getAttribute("PRICE") %>
</td>
</tr>
<tr>
<td> </td>
</tr>
</table>
</body>
</html>
I am getting the following error and I am stuck..
ERROR
message /index.jsp (line: 28, column: 4) Unable to find setter method for attribute: name
description The server encountered an internal error (/index.jsp (line: 28, column: 4) Unable to find setter method for attribute: name) that prevented it from fulfilling this request.
My understanding
Line 28 is <html:form action="Lookup" name="lookupForm" type="ch03.LookupForm" >
name on the index page represents the javabean data
type = the qualified path and name of the javabean
index.jsp
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<html>
<head>
<title>Wrox Struts Application</title>
</head>
<body>
<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/wxmainlogowhitespace.gif">
</div>
</td>
</tr>
<tr>
<td> </td>
</tr>
</table>
<html:errors />
<html:form action="Lookup"
name="lookupForm"
type="ch03.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>
JavaBean
package ch03;
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;
}
}
Controller
package ch03;
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;
public class LookupAction extends Action {
protected Double getQuote(String symbol) {
if ( symbol.equalsIgnoreCase("SUNW") ) {
return new Double(25.00);
}
return null;
}
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
Double price = null;
// Default target to success
String target = new String("success");
if ( form != null ) {
LookupForm lookupForm = (LookupForm)form;
String symbol = lookupForm.getSymbol();
price = getQuote(symbol);
}
// if price is null, set the target to failure
if ( price == null ) {
target = new String("failure");
}
else {
request.setAttribute("PRICE", price);
}
// Forward to the appropriate View
return (mapping.findForward(target));
}
}
struts-config.xml
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
"
<struts-config>
<form-beans>
<form-bean name="lookupForm"
type="ch03.LookupForm"/>
</form-beans>
<action-mappings>
<action path="/Lookup"
type="ch03.LookupAction"
name="lookupForm" >
<forward name="success" path="/quote.jsp"/>
<forward name="failure" path="/index.jsp"/>
</action>
</action-mappings>
</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"
"
<web-app>
<!-- Standard ActionServlet Configuration -->
<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>
<!-- Standard ActionServlet Mapping -->
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<!-- Standard Welcome File List -->
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<!-- Struts Tag Library Descriptors -->
<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>
</web-app>
quote.jsp
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<html>
<head>
<title>Wrox Struts Application</title>
</head>
<body>
<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/wxmainlogowhitespace.gif">
</div>
</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>
<bean:message key="app.price" />: <%= request.getAttribute("PRICE") %>
</td>
</tr>
<tr>
<td> </td>
</tr>
</table>
</body>
</html>