Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

servlets + including files

 
david allen
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
david allen
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic