Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Struts
Search Coderanch
Advance search
Google search
Register / Login
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
Paul Clapham
Ron McLeod
Jeanne Boyarsky
Tim Cooke
Sheriffs:
Liutauras Vilda
paul wheaton
Henry Wong
Saloon Keepers:
Tim Moores
Tim Holloway
Stephan van Hulst
Carey Brown
Frits Walraven
Bartenders:
Piet Souris
Himai Minh
Forum:
Struts
error in my struts application no getter methods
sahana mithra
Ranch Hand
Posts: 72
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Here is my entire code.
web.xml -------------------------- <?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <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>debug</param-name> <param-value>2</param-value> </init-param> <init-param> <param-name>detail</param-name> <param-value>2</param-value> </init-param> <init-param> <param-name>application</param-name> <param-value>ApplicationResource</param-value> </init-param> <load-on-startup>2</load-on-startup> </servlet> <servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <session-config> <session-timeout> 30 </session-timeout> </session-config> <welcome-file-list> <welcome-file>/Employee_Details.jsp</welcome-file> </welcome-file-list> <jsp-config> <taglib> <taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri> <taglib-location>/WEB-INF/struts-bean.tld</taglib-location> </taglib> <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-logic.tld</taglib-uri> <taglib-location>/WEB-INF/struts-logic.tld</taglib-location> </taglib> <taglib> <taglib-uri>/WEB-INF/struts-nested.tld</taglib-uri> <taglib-location>/WEB-INF/struts-nested.tld</taglib-location> </taglib> <taglib> <taglib-uri>/WEB-INF/struts-tiles.tld</taglib-uri> <taglib-location>/WEB-INF/struts-tiles.tld</taglib-location> </taglib> </jsp-config> </web-app>
struts-config.xml <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd"> <struts-config> <form-beans> <form-bean name="employeeForm" type="GradeForm"/> </form-beans> <global-exceptions> </global-exceptions> <global-forwards> <forward name="welcome" path="/Welcome.do"/> </global-forwards> <action-mappings> <action input="/Employee_Details.jsp" name="employeeForm" path="/employeeDetails" type="GradeAction"> <forward name="success" path="/success.jsp" /> <forward name="failure" path="/failure.jsp" /> </action> <action path="/Welcome" forward="/welcomeStruts.jsp"/> </action-mappings> <controller processorClass="org.apache.struts.action.RequestProcessor" /> <message-resources parameter="ApplicationResource"/> <plug-in className="org.apache.struts.validator.ValidatorPlugIn"> <set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/> </plug-in> </struts-config>
EmployeeDetails.jsp <%@page contentType="text/html" pageEncoding="UTF-8"%> <%@taglib uri="/WEB-INF/struts-html.tld" prefix="html" %> <%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title> <bean:message key="Employee_Details.title"/> </title> </head> <body> <div style="color:red"> <html:errors /> </div> <html:form action="employeeDetails"> <center> <h1>Employee Login </h1><br> <bean:message key="prompt.id"/> <html:text name="employeeForm" property="EmpID"/><br> <bean:message key="prompt.name"/> <html:text name="employeeForm" property="EmpName"/><br> <bean:message key="prompt.salary"/> <html:text name="employeeForm" property="EmpSal"/><br> <html:submit> <bean:message key="button.submit"/> </html:submit> <html:reset> <bean:message key="button.reset"/> </html:reset> </center> </html:form> </body> </html>
GradeForm.java import javax.servlet.http.HttpServletRequest; import org.apache.struts.action.ActionErrors; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionMapping; import org.apache.struts.action.ActionMessage; public class GradeForm extends ActionForm{ private static final long serialVersionUID = 1L; private String EmpID; private String EmpName; private int EmpSal; public GradeForm(){ EmpID=""; EmpName=""; EmpSal=0; } public String getEmpId(){ return EmpID; } public void setEmpId(String EmpID){ this.EmpID=EmpID; } public String getEmpName(){ return EmpName; } public void setEmpName(String EmpName){ this.EmpName=EmpName; } public int getEmpSal(){ return EmpSal; } public void setEmpSal(int EmpSal){ this.EmpSal=EmpSal; } public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { ActionErrors errors = new ActionErrors(); if (EmpName == null || EmpName.length() < 1) { errors.add("EmpName", new ActionMessage("error.EmpName.required")); } if (EmpID == null || EmpID.length() < 1) { errors.add("EmpID", new ActionMessage("error.EmpId.required")); } if (EmpSal<0) { errors.add("EmpSal", new ActionMessage("error.EmpSalary.required")); } return errors; } }
GradeAction.java 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 GradeAction extends Action { private static final String A = "A"; private static final String B = "B"; private static final String C = "C"; String grade=null; public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response){ GradeForm gf=new GradeForm(); int salary=gf.getEmpSal(); try{ if(salary>1000){ grade=A; }else if(salary>=5000&&salary<1000){ grade=B; }else if(salary<5000){ grade=C; } }catch(Exception e){ } return mapping.findForward(grade); } }
I get only the below error. Please help me
Dheeraj dubey
Greenhorn
Posts: 8
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
In your GradeForm class
instate of
public String getEmpId(){ return EmpID; }
Use
public String getEmpID(){ return EmpID; }
sahana mithra
Ranch Hand
Posts: 72
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi,
I changed as you told but still its not working...
Reyaz Ahmed
Greenhorn
Posts: 3
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
The name of the attribute in ActionForm must start with small letter like in this case
public class GradeForm extends ActionForm{
private static final long serialVersionUID = 1L;
private
String
empID;
private String empName;
private int empSal;
// and after that generate the getter and setter of the above attribute
}
I think it will solved your problem
Yes, my master! Here is the tiny ad you asked for:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
java.lang.NullPointerException in a simple servlet
org.apache.jasper.JasperException: Unable to load class for JSP
a question about struts....please help
Can you help a STRUTS newbie?
ERROR :: cannot find ActionMappings or ActionFormBeans
More...