• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

no getter method

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi am getting this following error
javax.servlet.ServletException: No getter method for property lastName of bean org.apache.struts.taglib.html.BEAN


My Form is
public class SubmitForm extends ActionForm {

private String lastName = "Hansen"; // default value
private String address = null;
private String sex = null;
private String married = null;
private String age = null;

public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
// Log the forms data
servlet.log("Lastname:" + lastName);
servlet.log("Address:" + address);
servlet.log("Sex:" + sex);
servlet.log("Married:" + married);
servlet.log("Age:" + age);

// Check for mandatory data
ActionErrors errors = new ActionErrors();
if (lastName == null || lastName.equals("")) {
errors.add("Last Name", new ActionError("error.lastName"));
}
if (address == null || address.equals("")) {
errors.add("Address", new ActionError("error.address"));
}
if (sex == null || sex.equals("")) {
errors.add("Sex", new ActionError("error.sex"));
}
if (age == null || age.equals("")) {
errors.add("Age", new ActionError("error.age"));
}
return errors;
}


/* Last Name */
public String getLastName() {
return (this.lastName);
}
public void setLastName(String lastName) {
this.lastName = lastName;
}

/* Address */
public String getAddress() {
return (this.address);
}
public void setAddress(String address) {
this.address = address;
}

/* Sex */
public String getSex() {
return (this.sex);
}
public void setSex(String sex) {
this.sex = sex;
}

/* Married status */
public String getMarried() {
return (this.married);
}
public void setMarried(String married) {
this.married = married;
}

/* Age */
public String getAge() {
return (this.age);
}
public void setAge(String age) {
this.age = age;
}


}
My jsp is
<%@ page language="java" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

<html>
<head><title>Submit example</title></head>
<body>

<h3>Example Submit Page</h3>

<html:errors/>

<html:form action="submit.do">
Last Name: <html:text property="lastName"/><br>
Address: <html:textarea property="address"/><br>
Sex: <html:radio property="sex" value="M"/>Male
<html:radio property="sex" value="F"/>Female<br>
Married: <html:checkbox property="married"/><br>
Age: <html:select property="age">
<html ption value="a">0-19</html ption>
<html ption value="b">20-49</html ption>
<html ption value="c">50-</html ption>
</html:select><br>
<html:submit/>
</html:form>

<logic resent name="lastName" scope="request">
Hello
<logic:equal name="submitForm" property="age" value="a">
young
</logic:equal>
<logic:equal name="submitForm" property="age" value="c">
old
</logic:equal>
<logic:equal name="submitForm" property="sex" value="M">
Man
</logic:equal>
<logic:equal name="submitForm" property="sex" value="F">
Lady
</logic:equal>
<bean:write name="lastName" scope="request"/>
</logic resent>

</body>
</html>
 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Provide struts-config entry too
 
rakshini nithya
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.0//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_0.dtd">

<struts-config>

<!-- ========== Form Bean Definitions ================= -->
<form-beans>

<form-bean name="submitForm"
type="com.cts.sample.SubmitForm"/>

</form-beans>

<!-- ========== Action Mapping Definitions ============ -->
<action-mappings>

<action path="/submit"
type="com.cts.sample.SubmitAction"
name="submitForm"
input="/submit.jsp"
scope="request">
<forward name="success" path="/submit.jsp"/>
<forward name="failure" path="/submit.jsp"/>
</action>

</action-mappings>

</struts-config>
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try changing:

<html:form action="submit.do">

to:

<html:form action="/submit">

If Struts can't match up the action path specified in the <html:form> tag to an action in the config file, it won't be able to find and instantiate the proper ActionForm bean. Sometimes it will find it even with the ".do" at the end, but I've found it's best to specify the action in the <html:form> exactly as it's defined in the struts-config.xml file.
 
The longest recorded flight time of a chicken is 13 seconds. But that was done without this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic