File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

no getter method

 
rakshini nithya
Ranch Hand
Posts: 39
  • 0
  • Mark post as helpful
  • send pies
  • 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>
 
vidya sagar
Ranch Hand
Posts: 580
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Provide struts-config entry too
 
rakshini nithya
Ranch Hand
Posts: 39
  • 0
  • Mark post as helpful
  • send pies
  • 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>
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic