This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Solution for repeating function in all servlets.

 
rammie singh
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • 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.
 
Nishan Patel
Ranch Hand
Posts: 689
Eclipse IDE Java Scala
  • Mark post as helpful
  • send pies
  • 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: 118
  • Mark post as helpful
  • send pies
  • 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
Eclipse IDE Java Scala
  • Mark post as helpful
  • send pies
  • 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.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic