Solved

Pull in passed variable to include in page include

Posted on 2003-11-26
16
951 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
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 arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

707 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

11 Experts available now in Live!

Get 1:1 Help Now