This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Struts and the fly likes No Getter method for LastName property of  bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "No Getter method for LastName property of  bean" Watch "No Getter method for LastName property of  bean" New topic
Author

No Getter method for LastName property of bean

Ramkumar Ramasubbu
Greenhorn

Joined: Jul 12, 2005
Posts: 4
Hi,

I am new to struts. I tried to run a simple struts application.
I am getting the following error.
javax.servlet.ServletException: No getter method for property LastName of bean org.apache.struts.taglib.html.BEAN
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:495)
at org.apache.jsp.submit_jsp._jspService(submit_jsp.java:97)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:92)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:809)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:162)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:240)


But i have getter/setter method for the property LastName.

Here is the SubmitForm class

package hansen.playground;
import org.apache.struts.action.ActionForm;


/**
* @author rramasub
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public final class SubmitForm extends ActionForm {

private String LastName = "Hansen";
private String Address;
private String Sex;
private String Age;

/**
* @return Returns the address.
*/
public String getAddress() {
return Address;
}
/**
* @param address The address to set.
*/
public void setAddress(String address) {
Address = address;
}
/**
* @return Returns the age.
*/
public String getAge() {
return Age;
}
/**
* @param age The age to set.
*/
public void setAge(String age) {
Age = age;
}
/**
* @return Returns the lastName.
*/
public String getLastName() {
return LastName;
}
/**
* @param lastName The lastName to set.
*/
public void setLastName(String lastName) {
LastName = lastName;
}
/**
* @return Returns the sex.
*/
public String getSex() {
return Sex;
}
/**
* @param sex The sex to set.
*/
public void setSex(String sex) {
Sex = sex;
}
}


Here is the Action class

package hansen.playground;
import org.apache.struts.action.ActionForm;


/**
* @author rramasub
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public final class SubmitForm extends ActionForm {

private String LastName = "Hansen";
private String Address;
private String Sex;
private String Age;

/**
* @return Returns the address.
*/
public String getAddress() {
return Address;
}
/**
* @param address The address to set.
*/
public void setAddress(String address) {
Address = address;
}
/**
* @return Returns the age.
*/
public String getAge() {
return Age;
}
/**
* @param age The age to set.
*/
public void setAge(String age) {
Age = age;
}
/**
* @return Returns the lastName.
*/
public String getLastName() {
return LastName;
}
/**
* @param lastName The lastName to set.
*/
public void setLastName(String lastName) {
LastName = lastName;
}
/**
* @return Returns the sex.
*/
public String getSex() {
return Sex;
}
/**
* @param sex The sex to set.
*/
public void setSex(String sex) {
Sex = sex;
}
}

Here is the Struts-Config.xml file

<struts-config>

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

<form-bean name="SubmitForm" type="hansen.playground.SubmitForm"/>

</form-beans>

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

<action path="/submit" type="hansen.playground.ActionClass"
name="SubmitForm"
scope="request">
<forward name="success" path="/submit.jsp"/>
<forward name="failure" path="/submit.jsp"/>
</action>
</action-mappings>

</struts-config>


I dont Know why i am getting this error.

Can anyone help me to resolve this issue?

Thanks for all your responses.


Regards
Ramkumar
Vasudhaiv Naresh
Ranch Hand

Joined: May 13, 2005
Posts: 57
Hi Ram!
I guess the ActionForm does not follow the bean's convention of naming properties:
->each property must begin with a lower case alphabet, and in case the property name has two words, the second word must begin with an upper case character.
Check replacing "LastName" property with "lastName".
Regards,
Naresh
Aash Patel
Greenhorn

Joined: Sep 14, 2005
Posts: 24
I agree with Naresh!
Ramkumar Ramasubbu
Greenhorn

Joined: Jul 12, 2005
Posts: 4
Hi Naresh and Patel,

Thanks for your response. But i tried the solution you gave. It's also giving me the same error.
Is there any other solution for this? If yes please help me withe solution.
S Bhanu
Greenhorn

Joined: Feb 28, 2005
Posts: 15
can u send the code snippet u r using in html?
Ramkumar Ramasubbu
Greenhorn

Joined: Jul 12, 2005
Posts: 4
hi Bhanu,

here is the code snippet for jsp page


<%@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>SubmitExample</title></head>
<body>

<h2>Example Submit Pageeeee</h2>


<html:errors/>
<html:form action = "submitPage">

Address: <html:textarea property = "address"/><br>
Sex: <html:radio property = "sex" value = "M"/>Male
<html:radio property = "sex" value = "F"/>Female<br>
Age: <html:select property = "age"/>
<htmlption value = "a">0-19</htmlption>
<htmlption value = "b">20-49</htmlption>
<htmlption value = "c">50-</htmlption>
</html:select><br>
<html:submit/>
</html:form>


</body>
</html>



Thanks for your efforts
Ergin Er
Ranch Hand

Joined: Sep 06, 2005
Posts: 60
It looks like you have cofigured the form bean as submitForm in struts config, but that you are calling a form named submitPage (which doesn't exist). Could you try changing that into submitForm?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: No Getter method for LastName property of bean
 
Similar Threads
Cannot retrieve mapping for action
Exception in Running Struts in Tomcat
can not be able to compile Action Class
Difficulty in re- rendering form data, eventhough no exception is thrown up
no getter method