Solved

Pull in passed variable to include in page include

Posted on 2003-11-26
16
965 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

This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
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…
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 how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

734 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