INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

trying to learn struts need help getting started using struts 1.3.10

trying to learn struts need help getting started using struts 1.3.10

trying to learn struts need help getting started using struts 1.3.10

(OP)
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>&nbsp;</td>
</tr>
<tr>
<td height="68" width="48%">
<div align="left">
<img src="images/wxmainlogowhitespace.gif">
</div>
</td>
</tr>
<tr>
<td>&nbsp;</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"
"http://jakarta.apache.org/struts/dtds/struts-confi...">

<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"
"http://java.sun.com/j2ee/dtds/web-app_2_3.dtd">

<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>&nbsp;</td>
</tr>
<tr>
<td height="68" width="48%">
<div align="left">
<img src="images/wxmainlogowhitespace.gif">
</div>
</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td>
<bean:message key="app.price" />: <%= request.getAttribute("PRICE") %>
</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
</table>
</body>
</html>


RE: trying to learn struts need help getting started using struts 1.3.10

(OP)
We were able to fix it. I delete the strike lines and it worked.

<%@ 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>&nbsp;</td>
</tr>
<tr>
<td height="68" width="48%">
<div align="left">
<img src="images/wxmainlogowhitespace.gif">
</div>
</td>
</tr>
<tr>
<td>&nbsp;</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>

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close