Jeff Storey
Software Developer
[url]http://jeffastorey.blogspot.com[/url]
Rather than having to include this in each and every page, investigate the use of a Servlet filter for such.Originally posted by Jeff Storey:
I have a site where each page includes an a file that checks if the user is logged in
Why would you expect different observable behavior? The file includes run-time activity so whether this activity is executed as part of an embedded script or run-time included script will yield no observable differences.However, what I've found is that this seems to behave the same way whether I use the include directive or jsp:include. Could someone help me understand why this is? Or if they shouldn't behave the same?
Jeff Storey
Software Developer
[url]http://jeffastorey.blogspot.com[/url]
Filters are the preferred way to perform common actions across a range of requests rather than embedding the same code (even include code) in each and every page. Additionally, when you progress to using modern best practices for web app structure -- in which page controllers gain access first before JSP pages -- includes are no longer a feasible way to perform "up front" actions.Originally posted by Jeff Storey:
Thanks for the clarification. The tip on servlet filters is a good one, thanks!
Sounds like a poor example to me. Any run-time action, such as obtaining a timestamp -- will execute just the same in either scenario.the examples I've seen mentioned deal with if you have an include file that prints out the current timestamp, that won't change if you include it using the include directive, but it will with jsp include. I'm not really sure I understand how these are different.
Let's say that you are going to use a bunch of custom tag libraries in your JSPs. So you collect all the necessary declarations into a single file that you can include on multiple pages. As these are required at compile-time, using the include action will not work because the included file will be processed at run-time rather than included at translation time when it is needed.Could you explain in a little more detail what you mean by compile time directive
Jeff Storey
Software Developer
[url]http://jeffastorey.blogspot.com[/url]
Other way around. if you are going to include directives that the page needs to compile, you must use the include directive. Trying to use the action will result in a translation error.Originally posted by Jeff Storey:
What would happen if you tried to include a file containing the custom tag library delcarations with the include directive as opposed to jsp:include.
Yes, you can't forward or redirect after a response has been committed. Yet another reason to use filters and to adopt modern best-practice web constructs. These patterns were created and adopted not just to make things complicated, but to solve real-world problems such trying to make decisions (like forwarding) way too late in the request/response cycle as you are running up against.Lastly, the reason I'm having these issues is because I tried to include my login page (while I now know I can use filters, let's just assume this is on a single page and not a login include on every page) using the jsp:include tag and I got an exception in Tomcat about the stream being closed. Some research led me to this article http://today.java.net/pub/a/today/2005/08/04/jspcomponents.html?page=3#jsp_servlets_compatibility so I'm not really sure what else to do aside from using the include directive.
Jeff Storey
Software Developer
[url]http://jeffastorey.blogspot.com[/url]
If I had asked people what they wanted, they would have said faster horses - Ford. Tiny ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
|