Solved

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

Posted on 2004-10-08
7
298 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 4

Expert Comment

by:indigostark
ID: 12259300
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
ID: 12259459
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
ID: 12274358
Hi,
  try using <jsp:include page="header.jsp" />
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 12296871
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
ID: 12349055
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
ID: 12481698
did this help? havent heard anything on this thread for a while.
0
 

Author Comment

by:DASARI_R
ID: 12504014
Siliconeagle,

It did work. Thanks for the example code..

Dasari
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Build and evolve an interactive experience 1 99
JavaScript parse form with colon separated values 2 78
Problem to Popup 2 91
collection output issue 9 59
Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

740 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