[JSP/Newbie]: howto write my own jsp:include tag?

Hi folks,
I'm trying to write a replacement tag for <jsp:include> (which shall later decide upon its context what to include..), i.e. I want to include another JSP from within a tag.
Unfortunately right now my best bet does not allow to control the position of the included JSPs output in my output stream - it prints directly :-((
// index.jsp is my startpage:
<%@ taglib uri="/cistags" prefix="cis" %>
index.jsp START:
<cis:include file="/theincludefile.jsp" />
index.jsp ENDE
// theincludefile.jsp is the included file
-->INCLUDEFILE<--
// include.java is my current idea to approach this:
public class include extends TagSupport {
private String jspName;
public void setFile(String name) {
this.jspName = name;
public int doEndTag() {
HttpServletRequest request =
(HttpServletRequest) pageContext.getRequest() ;
HttpServletResponse response =
(HttpServletResponse) pageContext.getResponse() ;
try {
request.getRequestDispatcher(
response.encodeURL(jspName)).include(request,response) ;
catch (Exception e) { }
return EVAL_PAGE;
the result expected is:
index.jsp START:
-->INCLUDEFILE<--
index.jsp ENDE
but instead I receive:
-->INCLUDEFILE<--
index.jsp START:
index.jsp ENDE
So how can I get hold of the ouput generated by the JSP I'm calling through RequestDispatcher.include so that I can rewrite it into my own output stream here?
Is someone out there able to point me into the right direction?
Ingo
[email protected]

check this article out
http://www.javaworld.com/javaworld/jw-09-2000/jw-0915-jspweb.html

Similar Messages

  • JSP newbie (from PHP)

    Hello!
    I want to re-write my php code into servlets or jsp.
    so, how do I do an include directive to include headers and footers such as in php with include("header.php") ?
    jason

    <jsp:include page="header.jsp" />

  • Rule Author-How to use own JSP screen instead of Rule Author Customization

    hi' I am using Oracle Business Rules and creating Rule Repository using Rule Author however
    I want to use my own JSP screen for customization of Rules instead of using Rule Author customization screen.
    please tell me how to do this.
    thanks
    Yatan
    Edited by: Yatanveer Singh on Jan 29, 2009 5:19 AM

    oracle provides API to edit rule repository programmatically. To use your custom JSP pages you need to write your wrapper classes over following oracle rule API classes:
    oracle.rules.sdk.editor.ruleset.Rule
    oracle.rules.sdk.editor.ruleset.RuleSet
    oracle.rules.sdk.editor.ruleset.Action;
    oracle.rules.sdk.editor.ruleset.AdvancedExpression;
    oracle.rules.sdk.editor.ruleset.Expression;
    oracle.rules.sdk.editor.ruleset.Pattern;
    oracle.rules.sdk.editor.ruleset.SimpleTest
    Once you create wrapper you can use them as pojos to build your custom rule author screen.

  • Unable to run jsp as include using jsp:include tag

    I am trying to run the basic jsp:include sample provided by Oracle in OC4J 10g. When I run the code, It seems like include file is treated as text/html and not run at all. Can somebody help me in figuring out what I am missing here..
    Here is the code for main.jsp
    <jsp:include page="content.jsp">
    <jsp:param name="a" value="1"/>
    <jsp:param name="b" value="2"/>
    <jsp:param name="c" value="3"/>
    </jsp:include>
    Here is the code for content.jsp
    <p> Included Content </p>
    <p> Parameters - ${param.a}, ${param.b}, ${param.c} </p>
    When I run this code in JDeveloper10g using the embedded OC4J as well as Application Server 10g, I get the following output.
    Included Content
    Parameters - ${param.a}, ${param.b}, ${param.c}
    Note that the parameter values are not substituted properly.
    Thanks in advance
    Niraj

    javax.servlet.ServletException: com/sun/tools/javac/Main (Unsupported major.minor version 49.0)
    This is your problem either your tomcat or eclipse is pointing to a wrong jre
    here the problem is you are trying to run a code that was compiled using j2sdk1.5 in j2sdk1.4

  • Problem with flush=true in the jsp:include tag

    Hello
    I have deployed a JSP based application , based on the apache struts framework. The web server is Sun One Webserver 6 Service Pack4, on a windows 2000 machine
    The same application was tried on SunONE application server 7, and it works without any problem. However in this case the following error , on the page
    javax:servlet.jspexception:Illegal to flush within a custom tag
    Does this mean flush="true" is not allowed within custom tags
    Or is there a workaround for this
    Any help is appreciated
    thanks
    - Aniruddha

    Hi,
    This is a known problem, ��flush before you include�� limitation in JSP 1.1.
    As a result, you have to state flush="true" every time you include a jsp using <jsp:include> tag if you are using JSP1.1.
    Fortunately, it is fixed in JSP1.2. The flush attribute controls flushing. If true, then, if the page output is buffered and the flush attribute is given a ��true�� value, then the buffer is flushed prior to the inclusion, otherwise the buffer is not flushed. The default value for the flush attribute is ��false��.
    Gary Wang
    Developer Technical Support
    SUN Microsystems
    http://www.sun.com/developers/support/

  • Jsp newbie having trouble using JSP's with Jdev 10.1.3

    Hi,
    Have been bashing my head for about two hours with this, if anyone can help will substantially improve my life.
    First off apologies if question is stupid or obvious I am a jsp newbie.
    Have been experimenting with using the Jsp Taglibrary for tabbed panes in a browser.
    http://www.ditchnet.org/tabs/
    I have followed all the installation instructions but in JDeveloper when I build I get the message
    Error(18,2): method setJspContext(javax.servlet.jsp.PageContext) not found in class org.ditchnet.jsp.taglib.tabs.handler.TabConfigTag
    Any idea what jar file I'm missing.
    I'm a bit lost, thanks

    Arrrrrrrrgh,
    Sorted my problem.
    Rebuilt project, works fine now, no idea what was going on (just generally!).
    Thanks for input Shay
    Mark

  • How can we write methods in Jsp ?

    I want to write methods in jsp in such a way that in one method I should have "Creating database connection" and in another method I want to create ResultSet and in another method I want to access the ResultSet.

    u can write methods in jsp using the following tag
    <%!
    public void myMethod()
    %>

  • Include tags within a JSP block (making readable code)

    I've created a page that includes segments of other pages based upon a condition passed via a parameter. Arg! Let me start over.
    My code looks something like this...
    <%
       String foo = request.getParameter( "action" );
       if ( foo == null ) {
    %>
          <jsp:include page="error.html" flush="true" />
    <%
       } else if ( foo.equals( "add" ) ) {
    %>
          <jsp:include page="add_user.jsp" flush="true" />
    <%
       } else if ( foo.equals( "help" ) ) {
    %>
          <jsp:include page="help.html" flush="true" />
    <%
       } else {
    %>
          <jsp:forward page="display_status.jsp" flush="true" />
    <%
    %>And obviously, this is kind of hard to read. Is there a way that I can do includes and forwards within the context of the JSP block itself? I'm looking for something like...
    <%
       if ( foo == null ) {
          this.include( "error.html", "true" );
       } else if ( foo.equals( "add" ) ) {
          this.include( "add_user.jsp", "true" );
       } ... else {
          this.forward( "display_status.jsp" );
    %>...which should hopefully be a lot more readable.

    for example
    <jsp:include page="text.jsp" flush="true" />
    is equivalent to
    <% JspRuntimeLibrary.include(request, response, "text.jsp", out, true); %>
    ugh...
    There should be more simple solution.

  • Each Vitrual Software server with own jsp

    Hi all,
    How to setup vitrual software server with its own jsp page
    I install jdk1.3.1 and iplanet server 4.1 sp8 done in sun machine with
    os 7,
    I config and test jsp ok in single host, but can't work to each vitrual
    host to run own jsp page
    somebody know. How to setup and config own jsp for each vitrual software
    in iplanet web server.
    Please help
    thank.

    I also did testing on same - struggling to get the same for last couple of months...
    I'm using iws6.0 with jdk1.3 on Win-XP box (just the testing box).
    say - docroot is D:/Servers/WWWRoot
    and for vs abc.com - D:/Servers/WWWRoot/VS/abc_com
    If there is no index.jsp in abc_com folder http://abc.com/index.jsp will give 404 (file not found)... if the index.jsp exists there... it will give 500 (server error)... I went through the internal details using FILEMON... the latter case is looking (checking) for abc_com/index.jsp till the JSP compiler is invoked... But this JSP compiler is looking for WWWRoot/index.jsp... (this means JSP compiler is not aware of virtual server concept)...
    Interestingly, if there is WWWRoot/index.jsp present and accessed earlier... http://abc.com/index.jsp will server WWWRoot/index.jsp :-(( only if abc_com/index.jsp exists...
    I am also confused - how to fix this.
    Any help will be appreciated...
    Regards,
    Sudhaker
    sudhaker@___yahoo___.com
    (remove underscores)

  • 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]

  • Scriptlet within a jsp:include tag

    In Jrun 2.3.3 you could include a scriptlet within a <jsp:include> tag like this:
    <%
    String language = "E";
    %>
    <jsp:include page="/Conditions<%= language %>.html"/>
    Since I have to programme for four languages on our site, I used this convenient way of including different language pages on the fly all over the site.
    I then had a problem with 2.3.3 so I got 2.3.8 and discovered that all of these jsp:includes with scriptlets didn't work any more.
    I hastily uninstalled 2.3.8 and have continued with 2.3.3 ever since, thinking that they would sort this out in 3.0., which they didn't.
    Presumably to deal with this when I want to upgrade JRun I will have to use a load of if{} statements instead, but for four languages I will need four if {} statements which is incredibly long-winded compared to the single line of code above.
    <%
    if(language.equals("E")){
    %>
    <jsp:include page="/ConditionsE.html"/>
    <%
    %>
    Can anybody help:
    1) by giving me a neater solution that the one I've come up with.
    2) by explaining what happened at JRun to cause this change.
    Thanks.

    I could be wrong, but at least with WSAD (WebSphere), I couldn't do this:
    <html:text maxlength="14" size="10" property="proofOfClaim[<%=memberAccountIndex%>].sentDate%>"/>
    but could do this:
    <% String property = "proofOfClaim[" + memberAccountIndex +"].sentDate"; %>
    <html:text maxlength="14" size="10" property="<%=property%>%>"/>
    I think the reason is that since <html:text> is a custom tag, any scriptlets <%=...%> must be the ENTIRE value, and not be inserted in the middle of a value, for an attribute. Try it out. :)

  • Flush in the jsp:include tag

    should I state flush="true" every time I include a jsp using <jsp:include> tag in a jsp pages? For example I am trying to include a menu bar on the top of every jsp pages. Should I flush the buffer every time? if not, will it affect the performance?
    Thank you
    Cal

    Hi,
    This is a known problem, ��flush before you include�� limitation in JSP 1.1.
    As a result, you have to state flush="true" every time you include a jsp using <jsp:include> tag if you are using JSP1.1.
    Fortunately, it is fixed in JSP1.2. The flush attribute controls flushing. If true, then, if the page output is buffered and the flush attribute is given a ��true�� value, then the buffer is flushed prior to the inclusion, otherwise the buffer is not flushed. The default value for the flush attribute is ��false��.
    Gary Wang
    Developer Technical Support
    SUN Microsystems
    http://www.sun.com/developers/support/

  • Jsp include tag 1.1

    Hi all,
    i am getting the following error if my code snippet has a <jsp:include> tag
    org.apache.jasper.JasperException: Invalid jsp:include tag
    i am using VAJ3.5.3 and i modified the hosts file to support jsp1.1.
    But when i change to jsp1.0 the code works fine and fetching me the page contents.
    Need inputs.
    Regards
    Ramesh Kesavanarayanan

    Hi kesavramesh,
    I think some time ago, you're looking for something like this
    - Can I use jsp includes inside the taglib ?-
    See point 1 and 2.
    -- Paul
    1. link:
    http://www.jguru.com/faq/view.jsp?EID=115446
    2. text from the link:
    Normally when you call one JSP page from another you have no significant access to the result of the called JSP. So if I have
    Hi, I like nice clean JSP output
    <jsp:include page="gobbledegook.jsp" flush="true"/>
    Doh!
    When it would be much nicer to be able to do this:
    <%@ taglib uri="blahblah" prefix="myTags"%>
    Hi, I like nice clean JSP output
    <myTags:cleanUp>
    <jsp:include page="gobbledegook.jsp" flush="true"/>
    </myTags:cleanUp>
    Wahoo!
    This can be accomplish with the tag class:
    public class TakeOutTheTrashTag extends BodyTagSupport
    public int doStartTag() throws JspTagException
    return EVAL_BODY_TAG;
    public int doAfterBody() throws JspTagException
    try {
    if (bodyContent != null) {
    String messy = bodyContent.getString();
    String clean = takeOutTheTrash(messy);
    bodyContent.getEnclosingWriter().print(clean);
    } catch (IOException ie) {}
    return EVAL_PAGE;
    public int doEndTag() throws JspTagException
    return EVAL_PAGE;
    private String takeOutTheTrash(String messy)
    String cleanedUp = messy;
    return cleanedUp;

  • Can we override jspinit,jspdestroy,jspservice methods in our own jsps?

    iam new to java.
    iam now learning these topics.
    can we override jspinit,jspdestroy,jspservice methods in our own jsps?
    plz send me with explanation.

    well, the JSP will become the content of the jspservice method.
    So yes, you can override that one (in fact there's no way you will NOT override it when creating a JSP :) ).
    But indeed, you should not even have the beginnings of any thought about "methods" or "overriding" anything when writing JSPs.
    You should not in fact use a single line of Java code when writing them.

  • Is it possible to add own JSP tags to the palette?

    Is it possible to add own JSP tags to the palette?
    Currently we are using other JSP tag library like Coldbeans, Display Tag Lib, and JSF tags like ourFaces, etc.
    And we have few own JSF tags and it would be good to keep them in JSC.

    http://www.youtube.com/watch?v=aKxw4_gv2vE
    DISCLAIMER: I haven't tried this myself, but I've seen it posted before.
    Matt

Maybe you are looking for

  • Not able to get the current data from the screen

    Hello All, I have created a table view on a value node.  I edit a field which has a date F4 help or a field DDLB and click SAVE. In the save event handler I am using get first statement in the loop and when I see the contents of the entity it is the

  • New HDD not showing in disk utility

    Help please! i can up on a broken G5 i have replaced the HDD. now i am trying to install tiger. but the new internal HDD is not showing up in disk utility. i plugged my passport in and it popped right up. some one please let me know what you think.

  • Un-purchased duplicates in library

    On one of my albums, the songs are duplicated, but the duplicates are un-purchased and have a 'buy' button beside them. I have tried to delete them but they are still in the library This is a screenshot of my library Does anyone have any ideas of how

  • Mouse tracking speed not saving in Lion

    Lion does not appear to remember/save my mouse tracking speed setting. I set it to a faster speed but it reverts every time I restart. Is there a .plist file somewhere that I can delete to maybe fix this? Anyone else experience this? Thanks.

  • 500 Internal Server Error and formsweb.cfg ???

    Hi I have the following message when I call my form application : 500 Internal Server Error Erreur de servlet de lapplication Forms. Valeur absente ou non valide pour le paramètre baseHTML. Vérifiez dans la configuration du servlet que cette valeur f