Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

include directive doubt?

 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,

Is it true that I can do <%@ include...anywhere in my jsp?? I tried doing this where I have a jsp ad I'm doing two includes in it and in the first include which I call start.jsp, I'm opening Hibernate transaction and I include this at the top of the page and in the end.jsp, I'm closing the hibernate transaction. Now when I include the end.jsp at the end of the page, I'm actually able to run index.jsp (the one which includes both start,jsp and end.jsp). But when I do the include for end.jsp somewhere else, I'm getting 500 error. One reason I can say is that I have some thing related to database happening in my index.jsp but before end.jsp (where I close the connection and so on).

My question here is what exactly happens when we include?? Can we do the include in any place or is it place sensitive?
 
PRavi kumar
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,

Using include directive we can include only static content. At the time of page translation time the include directive content will be pasted in original jsp.

It�s won't do any dynamic processing of request. It�s not a pace sensitive. We can use include directive in any place of your jsp.
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,

It is place sensitive....I tried testing it and when not in the correct place, it throws errors....
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,

I'm not talking about <%@ Page...., I'm talking about <%@ include....please note!
 
PRavi kumar
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes Jothi,

Your right
Include directive is place sensitive. it's just copy and paste the content wherever you included.
 
PRavi kumar
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes Jothi,

Your right
Include directive is place sensitive. it's just copy and paste the content wherever you included.
 
nitin pai
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The include directive is not, in nature, position dependent. It is in fact used to place partial content in a page wherever required.

But you must note that the partial content must be properly justified, i.e. You must know what comes before the directive and what comes after and based on that you should consider the positioning.

However if you do include some elements in the included page which when translated result in improper Servlet format then it is but obvious that will result in errors.

Try with plain HTML and then include this HTML page in a JSP page with the include directive. It wont matter then where it is placed!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic