This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem regarding <%@ include file=""%> and a Caching Filter  RSS feed

 
Anirban Chowdhury
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I have a problem here..I include a jsp file using <%@include file="/inc/navigationLinks.jsp"%> in another jsp.Now this navigationLinks.jsp is something like a banner which would appear on every jsp.

Now the problem is :

Firstly I want to use a cacheing filter which would store this navigationLinks.jsp in the cache for say 1hr. I have tried the below mapping in web.xml

<filter-mapping>
<filter-name>CacheFilter</filter-name>
<url-pattern>/inc/navigationLinks.jsp</url-pattern>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>

This does not work.The filter does not get called.

I have tried using the runtime include ie <jsp:include page="/inc/navigationLinks.jsp"/> .Then the filter does get called,but unfortunately as I use <bean:message> and <html:link> in the navigationLinks.jsp, I cannot use the runtime compile.
I want to use the compile time include and the filter @ the same time.. Somebody please help..

Thanks & Regards
Anirban Chowdhury



 
Ankit Garg
Sheriff
Posts: 9610
37
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Compile time include works when your JSP is compiled. The code of the included resource is copied into the calling code. So caching filter with compile time include doesn't makes any sense...
 
Anirban Chowdhury
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ankit, Thanks for your reply.
But could you please elaborate..If a header/banner JSP (eg. size .1 mb) is included @ compile time,and this banner is included in say 10 pages,then 1 MB of memory space is required. If I cache the banner the first time it loads,then only .1 mb is used.rite?? I thought that was the idea,and so I wanted to use a caching filter. Yes the code is copied every time,but it wont require a server hit,if I cache it,rite?
I might be wrong.Would really appreciate if you would explain the inadequacies.Thanks once again for your answer.
 
Ankit Garg
Sheriff
Posts: 9610
37
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes the code is copied every time,

No, the code is copied into the generated servlet for the JSP only once, not with every request...
 
swapnl patil
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes,Code is copied only once for include directive.
use Jsp:include or JSTL include tag <c:import url=""> then only your filter will get called.
 
Anirban Chowdhury
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ankit and Swapnil for your answers.I am sorry,maybe I did not make myself clear.What I meant by "copied every time" is that the header/banner jsp would be copied for every JSP page,not per request.
If pg 1 and pg 2 include the same banner say pg3, then when pg1 is requested,pg3 would be called and duly copied,when pg2 is requested ,pg 3 would again be called and copied. I want to prevent this second call from going to the server.Instead I want it to be present in my cache. Please correct me if I am wrong anywhere.Thanks once again for your replies.

P.S: Ok, just as I was posting this question,I thought of doing a small test.I put a small scriptlet(a Sysout) in the banner page pg3,and I requested pg1. pg3 was called and copied.I went to another page and then came back again to pg1. Again the scriptlet which belonged to pg3 was executed.That means it is also getting copied per request,is it not? Even I was of the opinion that it gets called only once per request,if you include it @compile time.
 
swapnl patil
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

If pg 1 and pg 2 include the same banner say pg3, then when pg1 is requested,pg3 would be called and duly copied,when pg2 is requested ,pg 3 would again be called and copied. I want to prevent this second call from going to the server.

you are still confused. all this happened compile time not run time . so your header page will get copied at compile time when you build your project.
all this happened when you used include directive.

But when you use jsp:include or jstl import tag then all these happened at run time means whatever you mentioned this happened at this time .

for more reference read Head First for Servlet & Jsp page number 446 in "using JSTL" chapter.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!