Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Solution for repeating function in all servlets.

 
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi every body.

i have section of code(function) which is repeating in every servlet and in every servlet this function is called.


what can i do so that i donot need to write this function in every servlet and could use this function in every servlet .
Thanks and regards.
 
Ranch Hand
Posts: 689
Scala Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi,

There is no need to make this method because ultimately you just get requestdispatcher object and that you can put your every servlet doGet or doPost method.

So, put it into doGet or doPost or remove that method.

Or if you don't want to make servlet for every request and set request dispatcher then use Front controller patterns.

Struts use that patterns so if possible then use framework which use Front controller patterns. That makes your life easy.



 
rammie singh
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
but i need to forward the request to other pages also depending upon different conditions

so i guess if i don't use a function i will have to create request Dispatcher object each time i want to forward it to some page .....because i guess same request Dispatcher object can not be used again and again.

i hope i am clear to to you all guys.


here is my code.




 
Nishan Patel
Ranch Hand
Posts: 689
Scala Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi,

That's why I am telling you to use framework which use Fornt Controller Design patterns.

Like Struts and Spring ..... use of that framework will reduce your work and same thing you want to implement they have already implement in in.

 
The problems of the world fade way as you eat a piece of pie. This tiny ad has never known problems:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic