Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2004-10-08
7
Medium Priority
?
301 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
Technology Partners: 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 1500 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

715 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