Dynamically include jsp:param

Is it possible to include <jsp:param> inside <jsp:forward> dynamically? There are two ways:
1)
<jsp:forward ...>
<% if (...) { %>
     <jsp:param ... />
<% } %>
</jsp:forward>
2)
<jsp:forward ...>
<util:if predicate="...">
     <jsp:param ... />
</util:if>
</jsp:forward>
assuming <util:if> is some kind of conditional evaluation tag.
The JSP 1.2 pfd2 says:
The jsp:param element is used to provide key/value information. This element is
used in the jsp:include , jsp:forward and jsp:params elements. A translation
error shall occur if the element is used elsewhere.
This seems to indicate that 2) is not allowed, but it is not clear whether or not 1) is allowed.
I think it is desirable to allow both methods of dynamically including jsp:param elements.
Any comments?

1. doesn't work. You're not allowed to have <% %> scriplets inside of a jsp:forward tag. You can however include <%= %> tags. So you could set the value of a parameter dynamically and include the in the jsp:param tag
2. I don't know about.
-Derek

Similar Messages

  • How to access a variable from a dynamically included JSP page

    I have a jsp (say main.jsp) using the following in its code :
    <jsp:include page="menu.jsp" flush="true" />
    I have a variable in menu.jsp which I would like to use in my main.jsp.
    How do I get the value of the variable defined in menu.jsp ?
    I called this variable in menu.jsp, Public, but this didnot help me use the value of that variable in main.jsp
    Any help is highly appreciated.. thnks a lot

    I do notice the variable var1 has the value populated - in menu.jsp - (from View -->
    Source in the browser) but for some reason not able to use it in main.jspI'm not quite sure of the way your jsps are structured from your code snippet but I think there is something to be aware of here that may be part of your problem, namely the difference between the include directive and the include action.
    You are currently using the include action, this treats the included resource as a dynamic object - i.e. a request is sent to that resource and the resulting response is included in your page. So when you think of what there is no java variable actually included - you'll just get the resulting HTML that is generated by menu.jsp
    The include directive, as in <%@include file=�menu.jsp � %>, on the other hand treats the resource as a static object. This means the actual bytes in the included resource are inserted into the including jsp and then the result of that is compiled and processed, effectively you are cutting and pasting the menu.jsp into your calling jsp. In this case the variable would be available to the calling jsp.
    However this approach does bring other difficulties that may break your current code, you'll just have to try it and see what happens.
    Hope that's relevant to your problem,
    Matt

  • How i will dynamically include jsp pages in a dynamic richfaces tab?

    Hello experts,
    I am unable to include jsp in dynamically created richfaces tab
    i am able to create the tabs sucessfully,but could not include the jsps in these tabs
    Please help???
    following is the code
              HtmlTab t;
                   t = new HtmlTab();
                   t.setId(id);
                   t.setName(id);
                                                    IncludeTag in=new IncludeTag();
                                                    t.setData(in);
                                                    tabpanel.getChildren().add(t);

    Another approach is to parse the blog's RSS feed into your HTML page with a PHP script.
    This is your wife's RSS feed:
    http://ninjabaker1.blogspot.com/feeds/posts/default?alt=rss
    Feed for All has a free script.  I just tested it and it seems to work ok with Blogger's RSS.
    http://www.feedforall.com/free-php-script.htm
    Nancy O.
    Alt-Web Design & Publishing
    Web | Graphics | Print | Media  Specialists 
    http://alt-web.com/
    http://twitter.com/altweb

  • Catch Exception for dynamic Include jsp:include

    I have a page (says pageA.jsp) that should include other file dynamically. (<jsp:include page="<%=includedFile%>" flush="true"/>)
    However, if there is error in the included file, can pageA.jsp redirect to the error page stated in the page attribute instead of including the error message in pageA.jsp?
    Thanks

    So here is a solution, not an optimal one I think but it should be ok if URL are all absolute. Note a "/" is add to be sure when including.
    <%
    if ( new java.io.File(application.getRealPath(aae.getUrlCont())).exists() ) {
    %>
    <jsp:include page='<%="/"+aae.getUrlCont()%>'/>
    <%
    } else {
    %>
    <jsp:forward page="/error.jsp"/>
    <%
    now, it is a valid code for html, jsp or others file type.

  • How to dynamically include jsp files using jsf el in include tag ?

    Hi,
    I'm trying to get the jsp file name from my backing bean to use it in an include tag but I can't make it work
    When using this piece of code I can get the generated path
             <h:outputText value="/_partial/#{myBean.jspName}.jsp"/>whereas in this code the jsf el is not replaced by this value.
            <%@ include file="/_partial/#{myBean.jspName}.jsp" %> Have you any idea of how to solve this ? I'm currently developing for J2EE 1.4 platform.     
    Thanks for your help,
    Regards.

    If you're using JSF 1.2 and JSTL 1.2 at a JSP 2.1 environment, then you can just use <jsp:include> with unified EL.
    If you're using JSF 1.1, then you may find this article useful [http://balusc.blogspot.com/2007/01/dynamic-jsf-subviews.html]

  • Dynamic include file in JSP page

    <span class="value">Hi
    i have index.jsp , this page can include jsp
    pages dynamically by passing the name of the page to be included to the
    index page with out .jsp , so if i want to include page "code.jsp" i
    put: .../index.jsp?page=code , this have to include code.jsp page
    i made the following code , but it did not find the file
    so can any one help plz ?
            String pg=request.getParameter("page");
            if( pg!= null && ! "".equals(pg)){
                    File f=new File(request.getParameter("page")+".jsp");
                    if(f.exists()){
                            out.print("file exist");
                            %>
                            <jsp:include page="<%=request.getParameter("page")+".jsp" %>" />
            <%
                    }else{
                            out.print("file not exist");
         

    What does the file existing or not really have to do with it?
    You can try it like this:
    String pg=request.getParameter("page");
            if( pg!= null && ! "".equals(pg)){
                    String webPath = pg + " .jsp";
                    String realPath = request.getRealPath(webPath);
                    File f=new File(realPath);
                    if(f.exists()){
                            out.print("file exist");
                            %>
                            <jsp:include page="<%= webPath %>" />
            <%
                    }else{
                            out.print("file not exist");
            }Alternatively you could try using a request dispatcher:
    RequestDispatcher rd = request.getRequestDispatcher(webPath);
    if (rd == null){
      // doesn't exist
    }

  • Trying to dynamic include HTML into a JSP

    All,
    I am trying to include an HMTL file into a JSP file. I wish to do this dymanically. So, the following is not an option:
    <%@ include file="relativeURL" %>
    So, I am forced to resort to such measures as the following:
    <jsp:include page="<%=myPath%>"/>
    However, I get the following error:
    java.lang.IllegalStateException: Response has already been committed
         at java.lang.Throwable.fillInStackTrace(Native Method)
         at java.lang.Throwable.fillInStackTrace(Compiled Code)....
    I tried it like this:
    <jsp:include page="<%=myPath%>" flush="true"/>
    I encoutered the same result. I have JSP 1.2 running Tomcat 3.1 with Apache 1.3.14, all on SunOS. Thanks in advance for any help.
    Nicholas

    One of the worst error messages you can get is the IllegalStateException. It simply means that an attempt has been made to forward or include but only a portion of the include was sent. In a situation like this the best way to handle the dynamic page content is to include it from a Servlet by sending the information you need through beans. Including the Servlet rather than the dynamic path would clear those errors right up. One thing to keep in consideration is that you can't just get the page and display it, you have to buffer it in so the state can be kept alive without timing out like it does with the dynamic include.
    Hope that helps. Been there, done that, I know how frustrating the error was.

  • Dynamic include in a custom tag, called from a jsp

    Hello, I would like to be able to dynamically include other jsp's from within a custom tag that I create. is this possible?
    in a jsp page i would just write <%@ include file="file.jsp" %> and all would be ok... but if i do an out.println( "<%@ include file=\"file.jsp\" %>" ); inside a custom tag bean then it doesn't work. it just prints out the command to the page as plain text.
    I do understand why this is happening, but can anyone offer me a way around this problem?
    Thanks in advance,
    Randy

    That's actually the same result as you get with a normal include - The method I suggested is a dynamic include similar to the <jsp:include> tag, not the <%@ include %> tag.
    When you use a dynamic include, the included page is compiled and 'invoked' as serarately, and the result is what gets included, not the actual source. To get the behaviour you want would require an include directive (the <%@ include %> tag) which I don't think has an equivalence you can use inside a custom tag.
    What you can do is pass attributes from the tag class like this:
    pageContext.setAttribute(<name>, <object>, pageContext.REQUEST_SCOPE);
    and then remove them after the include using pageContext.removeAttribute.
    I'm not certain, but this implies that if you declare your variables with a <jsp:usebean> tag with request scope, instead of normal Java variable declarations, you should be able to use them in the page included by the custom tag.
    *** in the jsp ***
    <jsp:useBean id="myVar" scope="request" class="java.lang.String" />
    <% myVar = "Something"; %>
    // Now call the tag which uses the pageContext.include() mehtod.
    *** end ***
    *** in the include ***
    <jsp:useBean id="myVar" scope="request" class="java.lang.String" />
    <%= myVar + " something else" %>
    *** end ***
    Let me know if it works.

  • Howto pass dynamic jsp:param value to applet

    Hi.
    I have a JSP page with 3 to 4 links... and an applet with jsp:plugin .
    So i want to pass the URL behind the link to the applet as a Request Param..
    My JSP code looks like
    <a link href="www.google.com">Google</a>
    <a link href="www.oracle.com">Oracle</a>
    <a link href="www.gmail.com">Gmail</a>
    <jsp:plugin type="applet"
                                code="MyApplet"
                                height="0" codebase="../../jars/" width="0"
                                name="MyApplet"
                                align="bottom">
                            <jsp:params>
                                    <jsp:param name="applicationURL"
                                               value="this should be the "/>
                            </jsp:params>
                            <jsp:fallback>
                                    <p>This feature should run on applet supported
                                       browser.</p>
                            </jsp:fallback>
                    </jsp:plugin>and my applet code looks like
    init()
              String appURL = getParameter("applicationURL");
                    System.out.println(appURL);
              }I have a similar thread in Java forums... Howto pass dynamic jsp:param value to applet
    Thanks,
    Murali.

    My JSP code looks like
    <jsp:plugin type="applet"
                                code="MyApplet"
                                height="0" codebase="../../jars/" width="0"
                                name="MyApplet"
                                align="bottom">
                            <jsp:params>
                                    <jsp:param name="applicationURL"
                                               value="applicationURL"/>
                            </jsp:params>
                            <jsp:fallback>
                                    <p>This feature should run on applet supported
                                       browser.</p>
                            </jsp:fallback>
                    </jsp:plugin>and my applet code looks like
    init()
              String appURL = getParameter("applicationURL");
                    System.out.println(appURL);
              }Now i want to have links on JSP pages clicking on which corresponsing url will be displayed in applet.
    Edited by: 635237 on Jan 24, 2011 10:44 AM
    Edited by: 635237 on Jan 24, 2011 10:45 AM

  • Jsp include and jsp param

    Hi All,
    I have the following:
    <jsp:include page="anotherPage.jsp">
            <jsp:param name="testing" value="sdfasdfsd"/>
    </jsp:include> And in anotherPage.jsp I have:
    <%@ taglib uri="/WEB-INF/tld/commons-log.tld" prefix="log" %>
    <log:dump scope="request"/>
    <log:dump scope="session"/>
    <log:dump scope="page"/>
    <log:dump scope="application"/>
    <h3>
    Test: <%= request.getParameter("testing") %>
    </h3>Not only does this output:
    Test: null
    but I don't see 'testing' anywhere in the dumps! What is going wrong?
    Have I badly misunderstood parameter sending? :-/
    Actually, my assumption was that the include code puts the "testing" variable
    into the request.. 1) where does jsp:param put the data items it
    passes through and 2) if the data item didn't previously exist as a
    request parameter, does it ignore it?
    Any assistance would be most appreciated!
    Rob
    :)

    Depends on the server version you are using. If you are using a JSP 2.0 server like Tomcat 5, then you should be able to do that, as long as you set up the container correctly (to use servlet 2.4 and JSP 2.0 specs rather than 2.3 and 1.2...)
    Is you are using a JSP 1.2 container (less then TC5) then you will not be able to use EL anyware except in JSTL tags. The fix is to use the JSTL tags to do the include:
    <c:import url="thepage.jsp">
      <c:param name="param1" value="${attr}"/>
    </c:import>

  • Send params to an included JSP page

    Hi,
    I don't understand that : I use Tomcat 4.0. When I write it :
    <!-- Affichage du fond de page ouvre la balise <body> (a refermer)  -->
    <jsp:include page="<%=JLdsWeb.URL_JSP + JLdsWeb.JSP_BACKGROUND%>" >
       <%-- Emp�che l'affichage de la barre de navigation --%>
       <jsp:p aram name="navigmenu" value="no" />
    </jsp:include>Tomcat send an error when compiling :
    Expected "param" tag with "name" and "value" attributes without the "params" tag.does someone know why ?
    an how can I solve this problem ?

    I came across this error for an entirely different reason. I had a param tag commented out in my code.
    So it read:
    <!--
    <jsp:include page="include/other.jsp>
    -->
    <jsp:include page="include/box.jsp">
    <jsp:param name="id" value="center"/>
    </jsp:include>
    It's really obvious when you look at it, but tied me up for a few minutes \^.^/

  • Problems with include jsp

    Hi... my english are not good enough but im trying to explain.
    I wanna include a url using <jsp:include tag, but my url have params.... so i know i have to use <jsp:param 4 each param.... So i did a little scriptlet that takes the url and separe each param to put it in a bidimensional array then i make a string with all the result... i mean... <jsp:inlcude page="relative URL" flush="true"><jsp:param name="hi" value="2"/>... next param... next param... </jsp:inlcude>.... i write the string at the jsp but it seems doesnt work.. this i made it with a document.write...
    the problem here is... the string its ok coz if i cut and paste the result i work great... but... if i make it dynamically ... nothing happens....
    Either i did put it the bidimensional array at the request.setAttribute for catch it at the next jsp and make a bucle for... but the same trouble... nothings happen...
    Some idea? :(

    You definitely want to use a jsp include action, not a directive. The directive
    happens at translation time and does not process the requested page. An action
    happens at request time and treats the requested page as a new request, thus
    including the results of the invoked jsp.
    BTW, the include action is the tags that looks line <jsp:inculde
    page="included_page.jsp" flush="true"/> or something similar (parameters can
    also be specified).
    The JSP 1.1 spec has more details. See sections 2.7.5 & 2.7.6 (for the include
    directive and a quick comparison of the directive vs the action) and 2.13.4 (for
    the include action).
    Matt
    Gurjit wrote:
    Hi ,
    I have a typical problem. The iplanet server doesn't interpret the code
    from a jsp which is included in another jsp. For eg.
    code for main jsp
    request.getParameter("username");
    <%@ include file="/jsp/ui/left_nav.jsp" %>
    processing code.
    Now when I start the server and the first time I load this page I get a
    dearranged page which has the code of the left_nav.jsp present in the html
    output.
    On opening this page to edit, when a small modification is made and the file
    is saved, a reload of the same page gives the proper output with all the
    jsp's interpreted.
    Thanks to one and all,
    Regards,
    Gurjit

  • Dynamically include variables...

    I have an application that is in 7 different languages. Based on client language setting I serve them up different content on the JSP pages. I basically have 7 resource files that look like this (each has different text for field1):
    <%
    String field1 = "English Text";
    %>
    I dynamically include this on each page like:
    <%
    String inc="includes/resources/"+ pageLang +".jsp";
    %>
    <jsp:include page="<%= inc %>" flush="true"/>
    This all works fine, no errors. The problem occurs when I try and call field1 on the main page:
    <%= field1 %>
    At this point I get an : Undefined variable: field1
    Does anyone have any idea why this would happen? Any ideas how to work around it?
    Thanks.

    You need to pass all your defined variables as parameters into your included jsp page. For this, you can use the following construct:
    <jsp:include page="spanish_content.jsp">     
       <jsp:param name="field1" value="<%= field1 %>" />     
    </jsp:include>These parameters can be then read in your included JSP by using the standard request.getParameter()-method. Unfortunately this requires you to convert your values into Strings and parse them back into their respective types inside the included page.
    You could also use the HttpSession to relay the parameters, although that may produce a bunch of problems. Do it like this in the including page:
    session.setAttribute( "field1", field1 );And in your included page:
    String field1 = (String) session.getAttribute( "field1" );For a better alternative for i18n, take a look at this:
    http://jakarta.apache.org/taglibs/doc/i18n-doc/intro.html
    .P.

  • Using a variable as a value in jsp:param

    I was wondering, I have a String variable, vid_1, and want to use a jsp:include and pass that in as one of the parameters. How can I do this? I have to do some testing to make sure vid_1 is valid and set a default if not. It contains a number referring to which video needs to be displayed.
    Is there anyway I can get this value to be used in jsp:param value?
    John

    RahulSharna wrote:
    Well,First thing you haven't pharsed your question properly.
    Anyways as per my understading.
    The first thing is make use of in this case as your defined requirement states you need to make use of variables of both the JSP's which need compile time include not at the runtime.use of
    <%@ include file="url" %>would be more appropriate as you want to use the variable of parent jsp to the child one.
    Anyways if you are thinking to apply a solution using <jsp:include/>
    <jsp:include page="url">
    <jsp:param name="paramName" value="<%=stringVariable>"/>
    </jsp:include>and extract the paramName's corresponding value as a request parameter in other JSP.
    Hope that might answer your question :)
    REGARDS,
    RaHuLRaHul,
    Thanks for the reply. The second example you gave is what I was trying to do. I thought I did exactly what you have there and it was not working. I will check it over again and post back on here when I have a chance.
    For now I was trying to use c:set to save the variable in the request and then using the EL expression ${requestScope.variable} to put it in the <jsp:param> element. I had some things working and others not when I quit. Hopefully tomorrow I can give you a full report and we can get this worked out.
    Maybe my problem is something else? Look at this post of mine:
    http://forum.java.sun.com/thread.jspa?threadID=5236252&tstart=10
    Thanks so much for the help.
    John

  • How can I do a dynamic include of a page fragment?

    I have a technical support website with a lot of simple html pages. What I want to do is hyperlink from the index page to another page, which would display these html pages as a page fragment, dynamically based on a session bean set by the hyperlink.
    I basically want to do this, if it was possible:
    <jsp:directive.include file="#{SessionBean1.pageToDisplay}"/>
    Now the FAQ's has a topic "How can I do a dynamic include of a page fragment?", which would seem to answer my question.
    But this is all it says, and it makes no sense to me. Could someone please translate? :)
    "Using a page fragment file (but using instead of the usual Creator approach) will accomplish a dynamic include."

    Here is 1 solution:
    First add this to the jsp:root tag:
    xmlns:c="http://java.sun.com/jsp/jstl/core"
    Then surround the page fragment directive with something like this:
                            <div style="position: absolute; left: 24px; top: 408px">
                                <c:if test="${SessionBean1.count > 0}">
                                    <jsp:directive.include file="testPF.jspf"/>
                                </c:if>
                            </div>

Maybe you are looking for

  • Attaching photos to discussions

    How do I attach photos in here? Been battling with this for a few days now. Sound like a daft question, probably is.:)

  • Preparing for the worst

    Sorry for the very basic question...just want to make sure I'm all set. I have Time Machine backing up just fine and has been for a while.  Just need to double check, were I to encounter a problem requiring a complete system rebuild, is my Tim Machin

  • Photos included in table don't print right

    I'm having trouble getting the photos (jpg's of about 700KB each) that I have embedded in a table to print right. I have them all set to "Image Fill" and "Scale to Fit". They look beautiful when I preview the print job, and the text prints just fine,

  • Xperia Mini Pro SK17a, when will ICS available ?

    After more than a year waiting for very annouced ICS update for 2011 Xperia mobiles, Sony has removed SI list with nothing for my Xperia Mini Pro [SK17a] SI 1249-8103. I´d like to say that I´ve chosen SK17a mobile because Sony officially annouced tha

  • Iphoto upgrade - photostream events

    I recently upgraded my iphoto to the new photos app. I noticed that photostream is no longer creating monthly events (as it did in iphoto) Is there a way to revert back to this option? I liked how my photostream would automatically create helpful mon