Solved

Pull in passed variable to include in page include

Posted on 2003-11-26
16
963 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
[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
  • 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
Industry Leaders: 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!

 

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
 

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

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Contact Forms for Website 6 85
Java Script nested call 3 89
React or Angular? 6 86
Why my table column Id is not passed to java object? 4 46
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…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
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:
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

749 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