0

I'm working on an servlet based project where I found that in a place, a value is set using request.setAttribute("") and in another place, that value is retrieved using request.getParameter(""). Is this right?

I know the difference between the getParameter and getAttribute. But the retrieved value intermittently becomes null.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Satthy
  • 109
  • 1
  • 3
  • 10
  • 2
    There is no way you can get the value from `request.getParameter` which has been set through `request.setAttribute`. Refer the link for for comparision http://stackoverflow.com/questions/5243754/difference-between-getattribute-and-getparameter. In your case, may be they are passing the same value in the query string also. – vjy Jul 03 '14 at 06:30

1 Answers1

1

Only those values can be retrieved using request.getAttribute which are set using request.setAttribute. And query string in GET request or request prameters in POST request can be retrieved using request.getParameter. There is no method as request.setParameter in Servlet API. Now coming to the intermittent behavior, check the URL/AJAX request on each request to server and see exactly when it has the property and its value set which you are trying to retrieve using getParameter method. Hope this clarify your issue.

Programmer
  • 325
  • 5
  • 18