Solved

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

Posted on 2004-10-08
7
299 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Tool to email me when a website changes 29 148
thymeleaf natural templating vs JSP 2 203
jsp login check 12 67
ejb on wildfly 5 64
It's sometimes a bit tricky to use date functions in Oracle BPEL. I'll explain quickly how you can add N days to the current date. In a BPEL process this can be useful, and you can adapt it to fit your needs. First of all, let's see how to add 1 …
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…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

759 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