Solved

Variable defined in a jsp are not available in the including file

Posted on 2004-10-08
7
295 Views
Last Modified: 2013-11-18
Hi All,

I have a header.jsp, viewBankInfo.jsp and footer.jsp.

header.jsp - has conn object in the scriplet <%Connection conn = DBMgr.getConnection(); %>
footer.jsp - should be able to close the conn "conn.close()"

ViewBankInfo.jsp - includes both header and footer.  I want to use "conn"  object in

<%@ include file="header.jsp"%>

conn.executeStmt();

<%@ include file="footer.jsp"%>

The problem is that viewBankInfo.jsp doesn't recognise variable declared in header.jsp. Isn't "include" directive allows us to use variables declared in including or included pages ?



Help would be greatly appreciated
Thanks
Dasari
0
Comment
Question by:DASARI_R
7 Comments
 
LVL 4

Expert Comment

by:indigostark
Comment Utility
How about placing the 'conn' object into the current HTTP request as setAttribute("conn", conn);
and calling getAttribute("conn") in your footer.jsp
0
 

Author Comment

by:DASARI_R
Comment Utility
Hi

Thanks for the quick response. There might be many variables that we want to use in across the pages. so i am not sure if we want to put all of them in the request object. But shouldn't the include option already gives us access to the variable. When the jsp is compiled into servlet it is compiled by including all the pages into one page. So the variables should be available.
0
 

Expert Comment

by:msasikala
Comment Utility
Hi,
  try using <jsp:include page="header.jsp" />
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
Comment Utility
ideally speaking include file should be working and you should be able to use the variable out there..
can you post the headr.jsp and bankinfo.jsp so that we can look in to it?
what is the exception you are getting while compiling??
0
 
LVL 2

Accepted Solution

by:
siliconeagle earned 500 total points
Comment Utility
it definitley should be <%@ include file="header.jsp"%>.

here are 3 files :-
header.jsp:
<%int i=0;%>
<%=i%>

footer.jsp:
<%=++i%>

and page.jsp
<%@ include file="header.jsp"%>
<%=++i%>
<%@ include file="footer.jsp"%>

the output is:-
0 1 2

you problem is likely to the syntax - I can have a look if you want.
what server are you using?
0
 
LVL 2

Expert Comment

by:siliconeagle
Comment Utility
did this help? havent heard anything on this thread for a while.
0
 

Author Comment

by:DASARI_R
Comment Utility
Siliconeagle,

It did work. Thanks for the example code..

Dasari
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now