• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Vijaya Ragavan
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9361
11
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!