• Post Reply Bookmark Topic Watch Topic
  • New Topic

Including Files Question  RSS feed

 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I have a header.jsp that I include at the top of every single page, and in the header.jsp I have an HTML BASE tag, does that BASE tag affect every page or do I have to put the BASE tag in every JSP anyway.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66144
144
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The base tag is interpreted by the client browser, so if it appears in an HTML page, it will affect the entire page. Which JSP pieces-parts are used to make up that page is immaterial.
bear
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bear. Works for me.
Another question on including files....
In order for the server to process the included JSP correctly, is there any reason we need any of the HTML markup in the page to be included.
For example, I have a footer.jsp that looks like:

Do I need any other HTML at the beginning and/or end for any reason or any special JSP tags of any kind?
Thanks.
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In general, no, but the answer does depend a little on which of the two types of "include" you are using.
I hope that for a job like this you are using <% @include file='footer.jsp' %>, in which case the file can be anything you like. I often give such included fragments a different file extension so I know they are not callable JSPs. Maybe footer.frag or something ?
If you are using the request-time include <jsp:include>, then your file must be servable from a server. In the case of a JSP, that means it must compile and execute, and generate something which can be included.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Frank. What if I am using the JSTL core taglib to import the files? Do I need to worry about anything with that?
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've just checked and if you are using <c:import> it's equivalent to a request-time include, and will be performed every time the page response is populated.
This sounds mad for something like a footer snippet of static HTML. especially as you have named it as a JSP - the container will have to compile it on deployment, and then run it every time the including page needs its static content. Yuck.
Is there any reason why you don't use the much more efficient compile-time include ?
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well (slap me) I have 1 dynamic bit in my footer for an Admin Console link. I guess I could create 2 footers, but this looks cleaner to me. So the footer isn't exactly static.
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There may be a way round this. Can you give any more details about how and when the "dynamic" bit of your footer actually varies?
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Frank Carver:
There may be a way round this. Can you give any more details about how and when the "dynamic" bit of your footer actually varies?

Yeah, it's easy. I will show you the code..

So basically, if the logged in user is an Admin, the link for Administration Console shows up. Otherwise, it doesn't.
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm..
Have you actually tried using the compile-time include? As far as I can tell, it should just work. All the code you show will just be included as if you had typed it into the calling JSP.
If for some reason it doesn't, there are loads of cunning tricks for simulating dynamism on static pages, depending on how much architecture flexibility you have Most of them assume that if an unauthorized user were to try and send a request for the admin console they would be blocked. I really hope you do this anyway, as you've got a big security hole otherwise. Most of them are also used to add dynamic advertising to static pages.
Idea one. Leave the button always on the page, but hide it with CSS.
If you have your page fetch a CSS stylesheet, you can generate the the CSS stylesheet itself using a JSP (or a servlet). This way it is easy enough to make the admin button invisible, off the screen or whetever, if the user is not authorized to see it.
Idea two. Leave the button always on the page, but hide it with Javascript.
Similarly, if your page includes an external JavaScript file, that can be tailored to the roles of the user.
Idea three. redirect "admin" users to a parallel URL tree
This is a trick I have used successfully to give the appearance of dynamic sites from a static web server. Normal pages might have URLs like
http://server/application/public/whatever.jsp
The same pages with the "admin" button have URLs like:
http://server/application/admin/whatever.jsp
In the "Logon" processing, simply redirect the logged in user to the appropriate URL-tree, and if an unauthorized user tries to request an "admin" page, just redirect to the public one.
This approach is a pain if you are hand-generating your pages, but if you are using a templating or code-generating site-builder tool to add your navigation and so on it should be pretty easy.
Idea four. split your footer
Put the dynamic bit into a bean or a custom tag to reduce the amount of code in the JSP, then just @include the static (copytright etc.) bit:

or

Has any of this helped?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!