File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Difference between getAttribute(string) and getParameter(String)
praveen kumar gowda
Joined: Feb 20, 2012
Feb 29, 2012 01:49:11
i come to know how get Parameter method works.....In that,
1)when we submit the form without fields value(empty form) ,will the value is null or empty?
please explain me about get Attribute method..i am not clearing of this..
Joined: Jan 18, 2012
Feb 29, 2012 06:43:17
1. When you use getParameter() method and send it as empty you will get Null pointer exception since null values are retrived.
And the difference between getParameter() and getAttribute() is ,
In getParameter you can retrive the values of the form.
Say you have
User Name:<input type="text" name="user1">
In the above code you can see the name="user1" this the key for us to take the user name type by the user. In next page you can get it as
String user= request.getParameter("user1");
Now you will get the user name typed by user.
If you have a
value in a page and you want to take it to next page that time we use getAttribute().
It will get the value from previous page as session
String user="Java Ranch"; session.setAttribute("name",user); // here the name is the reference to get in next page and user is the value that holds the string "Java Ranch"
Now in next page you will get the session as,
String Name = session.getAttribute("name").toString(); // here the reference name will retrieve the string value "Java Ranch" as a session
This is the difference ... Check the bold words for exact difference to say in one word
I agree. Here's the link:
subject: Difference between getAttribute(string) and getParameter(String)
Checkbox/Multibox validation in Struts
skipping JSF validation for reset event
Writing an Empty Line in a File....
need help urgently
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014