File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Solution for repeating function in all servlets. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Solution for repeating function in all servlets." Watch "Solution for repeating function in all servlets." New topic
Author

Solution for repeating function in all servlets.

rammie singh
Ranch Hand

Joined: Mar 26, 2009
Posts: 116
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

Joined: Sep 07, 2008
Posts: 684


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.




Thanks, Nishan Patel
SCJP 1.5, SCWCD 1.5, OCPJWSD Java Developer,My Blog
rammie singh
Ranch Hand

Joined: Mar 26, 2009
Posts: 116
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

Joined: Sep 07, 2008
Posts: 684


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.

 
wood burning stoves
 
subject: Solution for repeating function in all servlets.
 
Similar Threads
servlet path
RequestDispather
404 Error when trying to use a filter for a servlet
based on the output from the filter class, how do i mention which view page needs to be laoded
how to change URL?