File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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: 8997
    
    9

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.


[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