• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Good practice to send request and response objects in methods

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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











 
Author and all-around good cowpoke
Posts: 13078
6
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Bill.

Regards
Dev Anand. P
 
I'd appreciate it if you pronounced my name correctly. Pinhead, with a silent "H". Petite ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic