wood burning stoves 2.0*
The moose likes Struts and the fly likes Getting values of the Form inputfields in jsp to the action class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Getting values of the Form inputfields in jsp to the action class" Watch "Getting values of the Form inputfields in jsp to the action class" New topic
Author

Getting values of the Form inputfields in jsp to the action class

Vijaya Ragavan
Greenhorn

Joined: Dec 02, 2013
Posts: 25
I used a form with two Textfields for Name and Password.



My action class is:



When i tried accessing it in the action class, it throws NullPointerException when run. The error points to the line: if(this.username.equals("vijay") || this.password.equals("vijay")).

What is the problem here? Can't we access the variables from the action class instead of having a bean class?
Also i saw many tutorials using the Resource.properties file. Is it needed for getting values from the forms to the action class?


Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8707
    
    6

Vijaya Ragavan wrote:
What is the problem here? Can't we access the variables from the action class instead of having a bean class?


The name attribute of the textfield tag has to match the name of a property on the action. Getters and setters should be named "get" or "set" plus the name of a property, with the first letter following get/set capitalized. This convention is detailed in the JavaBeans Specification and allows Struts to use introspection to discover class properties at runtime.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting values of the Form inputfields in jsp to the action class
 
Similar Threads
validation using Resource Bundle
problems in validation part of struts 2
Struts 2 validation question
problems validation.xml in struts 2
Form Validation using xml in struts2