?
Solved

Access variable of parent jsp in included JSP

Posted on 2004-09-17
9
Medium Priority
?
1,244 Views
Last Modified: 2013-11-18
I have a JSP (A.jsp) which contains a variable declared like this :

<%! String returnToAction="abc"; %>

Now I include another JSP in this by writing

<jsp:include page="../common/B.jsp"  flush="true"/>

In B.jsp I want to access the variable declared in A.jsp,the code is as follows

<a href="/tradeability/edit_payment_info?fromPaymentReturnTo=<%= returnToAction %>"> Edit Payment Information</a>

This does not compile and says that unresolved symbol returnToAction.

Can anybody suggest wats wrong with that.
0
Comment
Question by:vishrutsumit
[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
9 Comments
 
LVL 28

Expert Comment

by:rrz
ID: 12087045
<jsp:include page="../common/B.jsp"  flush="true"/>      
This dispalys the output  of B.jsp  
Can you use the  include directive ?
<%@  %>
0
 
LVL 28

Expert Comment

by:rrz
ID: 12087085
You could try
<%@ include file="../common/B.jsp" %>
0
 

Author Comment

by:vishrutsumit
ID: 12087776
even the include directive doesn't work
0
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 
LVL 19

Expert Comment

by:ramazanyich
ID: 12088541
why do you use exclamation mark in your first JSP ??
Just use <% String returnToAction="abc";%>
0
 
LVL 21

Expert Comment

by:MogalManic
ID: 12091286
The problem is that the 'returnToAction' variable has a scope of the JSP page only.  When you leave the page in the @include directive, the variable does not exist.  The solution is to declare the bean in the REQUEST scope.  This can be done using the <jsp:useBean> tag.  Try the following:

<jsp:useBean id="returnToAction" class="java.lang.String" scope="request"/>
<%returnToAction="abc"%>
...
<jsp:include page="../common/B.jsp"  flush="true"/>


In the common/B.jsp:
<jsp:useBean id="returnToAction" class="java.lang.String" scope="request"/>
,,,
<a href="/tradeability/edit_payment_info?fromPaymentReturnTo=<%= returnToAction %>"> Edit Payment Information</a>

0
 

Author Comment

by:vishrutsumit
ID: 12112874
Logically this solutions should work.but it didn't,I had to use the param tags to pass the parameters.

Thanks all for your help.
0
 
LVL 10

Expert Comment

by:kupra1
ID: 12246214
I have used the same thing. It will work with the include directive.  It will not work with the include action tag as it will be included at the runtime and hence will throw the exception. Here is the example:
-------- (A.jsp)
<%@include file="B.jsp"%>
<html>
<head>
      <link href="css/styles.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#FFFFFF">
<%! String str = "Kupra"; %>
      <table border="1" width="95%" bgcolor = "#FFFFFF" cellpadding='0' cellspacing='0' bordercolor='#000000'>
            <tr>
                <td width="100%">
                               <table border="0" cellpadding="0" cellspacing="0" width="100%">
                                 <tr>
                                          <td align="center" bgcolor="#FF0000"><b><span class="Menu"></b><a
                                          href="servicerprofile.do" target='_parent'>My Account</a></td>
                                          <td bgcolor="#FF0000">&nbsp;</td>
                                          <td bgcolor="#FF0000">&nbsp;</td>
                                          <td align="center" bgcolor="#FF0000"><span class="Menu"><a
                                          href="linkcutofftime.do" target='_parent'>My Blogs</a></td>
                                          <td bgcolor="#FF0000">&nbsp;</td>
                                          <td bgcolor="#FF0000">&nbsp;</td>                              
                                    </tr>
                              </table>
                        </td>
            </tr>
      </table>
</body>
</html>


----- and (B.jsp)
<html locale="true">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="GENERATOR" content="Microsoft FrontPage 3.0">
<title>Exception</title>
      <link href="css/styles.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#FFFFFF">
<table border="1" width="95%" bgcolor = "#FFFFFF" cellpadding='0' cellspacing='0' bordercolor='#000000'>
  <tr>
    <td width="100%">
            Hello How r u?<%=str%>
      </td>
  </tr>
</table>
</body>
</html>


Look at the fact that the variable str used in the B.jsp is declared in A.jsp only and is being successfully used.

Thanks


0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 12531594
PAQed, with points refunded (125)

modulo
Community Support Moderator
0

Featured Post

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

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…
This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
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.
Suggested Courses

770 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