Solved

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

Posted on 2004-10-08
7
300 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
WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

 
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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
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…
Suggested Courses

624 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