Solved

Pull in passed variable to include in page include

Posted on 2003-11-26
16
960 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
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…
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 …

861 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