This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript 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: 8876
    
    8

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