Solved

Pull in passed variable to include in page include

Posted on 2003-11-26
16
954 Views
Last Modified: 2013-11-18
If I'm passing a variable from page A.jsp to page B.jsp named incName. How do I take it into page B.jsp and use it as an include for that page? For example

///////////////////////
A.jsp
--------
<a href="b.jsp?incName=myInclude.jsp">Click here</a>
///////////////////////

in page b.jsp I want to take the name of the include (myInclude.jsp) and use it  as an include for that page:
//////////////////////
b.jsp
----------
....
<jsp:include page="includes/<%incName%>" flush="true"/>
.....

/////////////////////
0
Comment
Question by:894359
  • 7
  • 6
  • 2
  • +1
16 Comments
 

Author Comment

by:894359
ID: 9826958
I have also tried something like this:
///////////////////////////////////

<jsp:include page="/includes/header.jsp" flush="true"/>
</div>
<% String incName = request.getParameter("incName"); %>


<% varincludefile ="includes/" + incName; %>
<jsp:include page="<%=varincludefile%>" flush="true">
<br><br>

<jsp:include page="/includes/footer.jsp" flush="true"/>
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 9827436
the page attribute of <jsp:include> does take RTValue. so this should work:

<% varincludefile ="/includes/" + incName; %>
<jsp:include page="<%=varincludefile%>" flush="true">

if not, let me know what error message you are getting.
0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 9829771
Ideally speaking there should not be any trick in this one.....
Only precaution you may want to take is to trim the incName value just to shake of any reduntant spaces at the start or at the end....
Do let us know what kind of errors you are getting...
0
 

Author Comment

by:894359
ID: 9833809
I get this error:

////////////////////

Error Message: /cust/WebSphere/AppServer/installedApps/brcd_partner.ear/brcd_partner.war/mjohns/BrocPartner/brcd_partner/content/For Technical Professionals/Downloads/Unsupported Tools Library Partner/details.jsp(24,0) JSPG0085E: Expected "param" tag with "name" and "value" attributes after the "params" tag.
0
 
LVL 14

Accepted Solution

by:
kennethxu earned 100 total points
ID: 9833931
woops, this should get you going:
<% varincludefile ="/includes/" + incName; %>
<jsp:include page="<%=varincludefile%>" flush="true" />

we forgot to close the tag!
0
 

Author Comment

by:894359
ID: 9834120
I'm now getting this:

////////////////
Error Message: /cust/WebSphere/AppServer/installedApps/brcd_partner.ear/brcd_partner.war/mjohns/BrocPartner/brcd_partner/content/For Technical Professionals/Downloads/Unsupported Tools Library Partner/details.jsp(28,0) JSPG0059E: Unable to compile class for JSP
////////////////////

do I need this in the top of the page??


<% String incName = request.getParameter("incName"); %>
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 9834140
the new error is indicating that the problem is in line 28, what is there?

>> <% String incName = request.getParameter("incName"); %>
for sure that you need to get incName declare and populated with right value. if  you still have problem, post the entire page.
0
 

Author Comment

by:894359
ID: 9834282
<jsp:include page="/includes/header.jsp" flush="true"/>
</div>
<% String incName = request.getParameter("incName"); %>
<style>
.subHeadUnsupportedTool      {
      color:            #330066;
      font-family:       verdana, arial, helvetica, sans-serif;
      font-size:       12px;
      font-weight:      bold;
      font-style:      normal;
      margin:            0;
      padding-left:      12px;
      padding-top:      6px;
      padding-bottom:      6px;
      }
.alignpadding      {
      padding-left:      12px;
      padding-top:      8px;
      padding-bottom:      8px;
      }
</style>

<% varincludefile ="includes/" + incName; %>
<jsp:include page="<%=varincludefile%>" flush="true" />
<br><br>

<jsp:include page="/includes/footer.jsp" flush="true" />
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:894359
ID: 9834288
LINE 28 is after the last line????
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 9834607
the code looks good, are you sure that this is the code that you actually using? it has only 27 lines.
would you post all the detail of error message.
0
 
LVL 4

Assisted Solution

by:kokchoon78
kokchoon78 earned 400 total points
ID: 9834845
Just make some modification :

<jsp:include page="/includes/header.jsp" flush="true"/>
</div>
<% String incName = request.getParameter("incName"); %>
<style>
.subHeadUnsupportedTool     {
    color:          #330066;
    font-family:      verdana, arial, helvetica, sans-serif;
    font-size:      12px;
    font-weight:     bold;
    font-style:     normal;
    margin:          0;
    padding-left:     12px;
    padding-top:     6px;
    padding-bottom:     6px;
    }
.alignpadding     {
    padding-left:     12px;
    padding-top:     8px;
    padding-bottom:     8px;
    }
</style>

<%
  if( incName != null )
  {
      String varincludefile ="includes/" + incName; %>
%>
     <jsp:include page="<%=varincludefile%>" flush="true" />
<%
  }
%>
<br><br>

if you still get errors, please check the 'varincludefile' and 'incName' variable.

0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 9835223
>>>>>>>>>><jsp:include page="/includes/footer.jsp" flush="true" />
>>>>>>>>String varincludefile ="includes/" + incName; %>
Are we sure we are not missing an '/' here while creating varincludefile???????? Just try
String varincludefile ="/includes/" + incName; %> as see if that helps.
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 9837339
kokchoon78 and kuldeep, the error is complie time error so it should be something else instead of the value of vars, which will only cause problem in runtime.
0
 

Author Comment

by:894359
ID: 9852344
Sorry for the delay.. I went to Las Vegas for the weekend! :)

The include path is correct. It  shouldn't have a leading "/"
0
 

Author Comment

by:894359
ID: 9852502
kokchoon78 solution worked??? I don't know what the main difference is but it worked!
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 9855584
I think the problem is actully this line:
<% varincludefile ="includes/" + incName; %>
it should be
<% String varincludefile ="includes/" + incName; %>
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

When you work with shopping cart / ecommerce relates web sites, you need to pass the certain form post details to the payment gateway process page with required details for the products items you give to order. Also you may need to track the ordered…
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
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:
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

895 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now