wood burning stoves 2.0*
The moose likes Servlets and the fly likes servlets + including files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "servlets + including files" Watch "servlets + including files" New topic
Author

servlets + including files

david allen
Ranch Hand

Joined: Sep 27, 2002
Posts: 185
Hi all,
I have a session validaion function that I would like to include in each servlet. I know the syntax to do this in jsp but how do I do it in a servlet. Also should the file just be a simple text file or a jsp file?
thank you david allen
Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
david-
I do not understand your question. If you say you have the validation in your jsp, then it'll be almost the same in your servlet (assuming it's a java-validation).
Also should the file just be a simple text file or a jsp file?
what file?


I'm not going to be a Rock Star. I'm going to be a LEGEND! --Freddie Mercury
david allen
Ranch Hand

Joined: Sep 27, 2002
Posts: 185
OK my question is.
What is the syntax that allows one to include a file into a servlet. Just say I have some code that is required by each servlet and I want to embed the code at the beginning of the servlet.
How do I do that?
Regards david
Sainudheen Mydeen
Ranch Hand

Joined: Aug 18, 2003
Posts: 218
Hi David
You may use RequestDispatcher's include(req, res) method. But it is still not clear what code you want to include.
------------
Sainudheen
david allen
Ranch Hand

Joined: Sep 27, 2002
Posts: 185
Ok here it is.
In a JSP page you can can use the include directive to include the contents of a file in the jsp page. The file that you want to include may contain a function of some kind.
This is all I want to do but do it in a server. I have several servlets that all require a function in them. I want to write that function in a single file then include the file in all of the servlets thus including the function. The function will validate a session that is all.
Thanks david
Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
I finally got you (I think so).
the solution is what Sainudheen suggested. the include will execute the "included" file and it will return to the page from where it was called.
HTH
 
jQuery in Action, 2nd edition
 
subject: servlets + including files