• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Good practice to send request and response objects in methods

 
Dev Anand
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got the following code in which i send request n response object to methods.

Is it a good practice to send these objects or shall i write the code here itself.

Thanks in advance






/*--------------------------Code Start------------------------------*/

if (s.equals("UserGroups"))
{
UserGroups(request,response);
}
else if(s.equals("updategroup"))
{
updateGroup(request,response);
}
else if (s.equals("DeleteGroups"))
{
DeleteGroups(request,response);
}
else if(s.equals("UserContacts"))
{
userContact(request,response);
}

/*---------------------------------Code End------------------------------*/


Regards


Dev Anand. P











 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13055
6
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it a good practice to send these objects or shall i write the code here itself.


Within your servlet class it is ok, but it is a questionable practice to pass request and response references to other classes because these are container managed objects. Sloppy programming can leave your code hanging on to a request or response longer than it should.

Instead of passing request to another class, use the javax.servlet.ServletRequest getParameterMap method and pass the resulting Map. By working with a Map you will have code that can be tested outside the servlet environment.

Bill
 
Dev Anand
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Bill.

Regards
Dev Anand. P
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic