Win a copy of Spark in Action this week in the Open Source Projects forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

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

 
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?


 
Bartender
Posts: 9612
16
Mac OS X Linux 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.
 
I am mighty! And this is a mighty small ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic