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.

Similar Messages

  • Exceptions thrown after a jsp:include

    Hi all,
              At the beginning of my JSP, I can't use the JSP include directive because I
              need to do a specific include from another webapp servlet context. Thus I
              wrote my own include tag <mytag:include page="" context=""/> where I use
              RequestDispatcher.include().
              But then I am facing the following problem with this JSP :
              [myjsp.jsp]
              <mytaglib:include page="" context=""/>
              <mytaglib:stgElse/>
              if the second tag <mytaglib:stgElse> is throwing a JspException, and if I
              use the error handling system of the webapp :
              [web.xml]
              <error-page>
              <exception-type>javax.servlet.jsp.JspException</exception-type>
              <location>/web/en/pf/error.jsp</location>
              </error-page>
              I get : "java.lang.IllegalStateException: Cannot forward a response that is
              already committed"
              because it tries to do a forward after an include which needed a flush of
              the buffer previously, what means the response was already comitted.
              Thus the question is : how to handle exceptions coming after an include was
              done, that is to say after a flush of the buffer has already been committed
              Thanks for any help.
              Yann
              

    In the doc, it states:
    sendRedirect
    If the response has already been committed, this method throws an
    IllegalStateException. After using this method, the response should be
    considered to be committed and should not be written to.
    In other words, you must not do anything before or after with the response.
    Cameron Purdy, LiveWater
    "Lawrence Lourduraj" <[email protected]> wrote in message
    news:8ip9p4$r0g$[email protected]..
    >
    Friends,
    How do I do a redirect either through HttpServletResponse.sendRedirect ()or
    <jsp:forward /> in a JSP that does a <jsp:include /> at the top.
    I am getting a IllegalState exception.
    Thanks
    Regards
    Lawrence Lourduraj
    VocaLoca Inc.

  • Writing JSP dynamically & using  JSP includes

    Need help with this one --
    I am pulling data from various fields of the DB and then placing the data into session vars so that based on what a user selects, the right information is displayed.
    My problem is this - I want to be able to display a jsp include file based on what the user selects. So the flow would go something like this
    EXAMPLE
    // USER selects a fruit (from a drop-down form) --> apple
    "apple" is stored in session var named fruit.
    // USER SUBMITS and expects to see a page based on his <%=fruit %> selection.
    //show_page.jsp
    I want to use the include tag that will call the right page based on the user selection -- like this:
    <%@ include file="<%= fruit%>.jsp" %>
    And in my thinking this would return - <%@ include file="apple.jsp" %> and thus include the right file for the user.
    Anyone know if embeding JSP to include a session var is possible?
    Thanks for any help
    Mark
    I know my synax is wrong. It's like I'm trying to embed a JSP tag inside inside a JSP include tag.
    Is there any way to do this

    learn the syntax...you won't get so many errors.
    "Professional JSP", WROX Press is great.
    scriplets ("<%....%>") can't have action tags in them.
    example:
    <%
    String include = "some_page.jsp"
    %>
    <jsp:include page="<%=include%>" />
    good luck.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • How to catch exception for class CL_HR_RE512W for method CHECK_CUMULATION

    Hi,
    How do I catch an exception when using method CHECK_CUMULATION in class CL_HR_RE512W.
    This method calls an instance method READ which raises NO_ENTRY if a wage type is missing on T512W.
    There is no obvious catch class to use?
    My code:
    data: r_512w type ref to cl_hr_re512w.
    start-of-selection.
    create OBJECT r_512w.
    call method r_512w->check_cumulation
    exporting
        p_molga  = molga
        p_lgart  = lgart
        p_cumul  = cumul
        p_date   = date
    receiving
          p_has_cumulation = p_flg.
    If lgart = '9999', for example, then we get an error message:
    'No entry in table T512W for key 08 9999 25.08.2009'

    Hi Gemini Twin,
    Check this link:
    https://wiki.sdn.sap.com/wiki/display/Snippets/ABAP+Objects+-+Defining+a+Class-based+exceptions
    Hope this information is help to you.
    Regards,
    José

  • MethodnotFound Exception for dynamically created component(menuItem)

    Hi
    I have created menuItem component and tried to create Action Listener object and setting it to the component in the backing bean.
    but it is throwing methodnot found exception.
    javax.el.MethodNotFoundException: Method not found: [email protected]()
    javax.faces.el.MethodNotFoundException: javax.el.MethodNotFoundException: Method not found: [email protected]()
         at com.sun.faces.application.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:92)
    Below is my code..
    MenuItem item1 = new MenuItem();
    item1.setValue(key);
    Application app = FacesContext.getCurrentInstance().getApplication();
    javax.faces.el.MethodBinding actionListener = app.createMethodBinding("#{breadCrumbBean.test}", null);
    item1.setActionListener(actionListener);
    Let me know whether i created actionListener object or not.
    Any suggestions...
    Thanks
    Edited by: _user on Jan 20, 2011 9:27 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Hi,
    I tried this it works for me...
    Try to set as below...
    MethodExpression ee = context.getApplication().getExpressionFactory().createMethodExpression(context.getELContext(), "#{breadCrumbBean.test}", String.class, new Class[] { });
    item1.setActionExpression(ee);
    Regards,
    Suganth.G

  • Relatiive Path problem when using JSP:include in web portlet

    Hi
    I am using Oracle Portal 9.0.2, and thus OC4J as the J2EE platform.
    I have created a JSP web portlet that is supposed to inlude a specific static html file, which name is passed to it using a portlet parameter. It works, but I had to create a symbolic link from the applicable J2EE applications's htdocs directory in order to access the content:
    /j2ee/OC4J_Portal/applications/<application>/htdocs/<portlet>/content/
    where /content/ is a symbolic link to another directory altogether.
    I can then access the content from within the portlet with a JSP include tag that looks like :
    docPath = "/htdocs/<portlet>/html/"+doc_path;
    %>
    <br>Include:
    <jsp:include page="<%=docPath%>" flush="true"/>
    I would like to access the content using the JSP include without having to use the symbolic link. Is there a way to do this. I tried using an Apache alias, but that did not work.
    Regards
    Harry

    Hi
    Thanx
    In the end we build up a static URL to the document to be included using:
    String contentLocation="content/";
    docPath = contentLocation+getAdditionalDocPath();;
    out.println("docPath="+docPath);
    String docPathAndName = portletRequest.getParameter("doc_path");
    %>
    <!--
    This java script function calls the display content page with the
    page parameter doc_path (which is in return passes it to the display
    content portlet) in order to retrieve and display specific document
    with a JSP:include tag
    -->
    <script language="JavaScript">
    function generateSectionPath(docName) {
    this.location="http://<%=portletRequest.getServerName()%>:<%=portletRequest.getServerPort()%>/pls/portal/url/page/<%=getPageGroup()%>/content?doc_path="+"<%=docPath%>"+docName;
    <script language="JavaScript">
    function generateRelativePath(docName) {
    this.location="http://<%=portletRequest.getServerName()%>:<%=portletRequest.getServerPort()%>/pls/portal/url/page/<%=getPageGroup()%>/content?doc_path="+docName;
    </script>
    <br>Include:
    <%
    if (portletRequest.getParameter("doc_path") == null) {
    out.println("Error - no doc path specified");
    } else { 
    try { %>
    <jsp:include page="<%=docPathAndName%>" flush="true"/>
    <% } catch (Exception e) {
    out.println("Error retrieving document:"+e.toString());
    } // end if
    %>
    Each link from one included HTML file to another becomes a JS function that points the browser to the portal page that includes the portlet that includes thwe JSP that has the include tag to include the html document that is to be displayed.
    The current relative path the the html document (from a predefined root in the file system that is symbolically linked to the same directory as where the including JSP lives) is stored in a session variable, and appended to the document name that is passed to the page.
    If a full document path, as opposed to just the name, is stored, that no appending is done. However, the path is stripped out and stored in a session variable.
    Ths thing is, sometimes a document name, and sometimes a path is passed to the page. Therefore the requirement to know the path when it is not available. A name only will always be passed subsequent to a request for a document with the full path specified, therefore the session variable mechanism works.
    Thanx for the input
    Harry

  • Jsp:include problem in custom tag

    I call <jsp:include page="emailbody.jsp" /> within a custom tag(in a file
              caller.jsp), which does emailing.
              When I invoke caller.jsp from browser, I do get the output(body of the
              email) on the browser screen, but not the output is not send as the body of
              the email.
              When I use static include namely, <@include file="emailbody.jsp" />, the
              output is directed to the body of the email.
              The above means, for a static jsp include file, it is parsed and included in
              the body-evaluation of the custom tag.
              For a dynamic include file, it is NOT parsed and NOT included in the
              body-evaluation of the custome tag.
              The reason could be, How Weblogic loads classes for custom-tag for dynamic
              include files.
              Can anybody at BEA throw loght on this and the solution.
              Thanks in advance.
              Chandra
              

    Well I found out jsp:include is not supported inside custom tags for JSP
              spec 1.1.
              This was stated in section 5.4.5 of spec 1.1.
              May be in future spec 1.2.
              Thanks
              Chandra
              "Cameron Purdy" <[email protected]> wrote in message
              news:[email protected]...
              > Have you sent this to [email protected]?
              >
              > It sounds serious.
              >
              > Peace,
              >
              > --
              > Cameron Purdy
              > Tangosol, Inc.
              > http://www.tangosol.com
              > +1.617.623.5782
              > WebLogic Consulting Available
              >
              >
              > "matthew mcclain" <[email protected]> wrote in message
              > news:[email protected]...
              > > I have run into the same problem.
              > > I'm certain it's because CustomTags have their own buffer and
              > > jsp:include or pageContext.include() or requestDispatcher.include()
              > > all bypass the buffer and write to the underlying stream.
              > >
              > > I attempted to define jspx:include by wrapping the response object
              > > which is sent to requestDispatcher.include and then wrapping the
              > > OutputStream returned from the response with a stream which
              > > writes to the "out" of the pageContext for my tag.
              > >
              > > Unfortunately, I get a class cast exception because weblogic expects
              > > it's own class to be there as a ServletOutputStream:
              > >
              > > java.lang.ClassCastException:
              com.allmystuff.wif.IncludeServletResponse$1
              > > at
              > >
              >
              weblogic.servlet.internal.RequestDispatcherImpl.include(RequestDispatcherImp
              > > l.java:202)
              > > at
              > >
              >
              weblogic.servlet.internal.RequestDispatcherImpl.include(RequestDispatcherImp
              > > l.java:172)
              > > at com.allmystuff.wif.Include.doStartTag(Include.java:37)
              > >
              > > So any chance, jsp:include will get fixed?
              > >
              > > Thanks,
              > > Matthew McClain
              > > [email protected]
              > >
              > >
              > > "chandra" <[email protected]> wrote in message
              > > news:[email protected]...
              > > > I call <jsp:include page="emailbody.jsp" /> within a custom tag(in a
              > file
              > > > caller.jsp), which does emailing.
              > > > When I invoke caller.jsp from browser, I do get the output(body of the
              > > > email) on the browser screen, but not the output is not send as the
              body
              > > of
              > > > the email.
              > > > When I use static include namely, <@include file="emailbody.jsp" />,
              the
              > > > output is directed to the body of the email.
              > > >
              > > > The above means, for a static jsp include file, it is parsed and
              > included
              > > in
              > > > the body-evaluation of the custom tag.
              > > > For a dynamic include file, it is NOT parsed and NOT included in the
              > > > body-evaluation of the custome tag.
              > > > The reason could be, How Weblogic loads classes for custom-tag for
              > dynamic
              > > > include files.
              > > > Can anybody at BEA throw loght on this and the solution.
              > > > Thanks in advance.
              > > > Chandra
              > > >
              > > >
              > >
              > >
              >
              >
              

  • 3 level jsp include

    I did a "framework" jsp file, because I have a bunch of pages, that need to look the same, except for the content.
    "framework" pseudo code:
    DoStuff
    *include file X;*
    DoSomOtherStuff
    *include file Y;*file X depends on the jsp including this framework, example:
    myFirstPage.jsp:
    X = "myFirstPartX.jsp";
    Y= "myNextPartY.jsp";
    <%@ include file="framework.jsp" %>Ok, so what type of include can I use in the framework to include X and Y files?
    I didn't find any way to create constants in MyFirstPage.jsp that I could use in the include directive so I have to use the jsp:include taglib, where X and Y are variables.
    Super, my only problem with the jsp:include is:
    - it is more resource consuming isn't it?
    - I cannot access variables I declared in myFirstPage.jsp
    - a can only pass objects to myFirstPartX.jsp and myNextPartY.jsp via the request.setAttribute
    It's seems like a trivial problem, being able to use a different include directive based upon the top level page (macros, constants?), is there no better solution than a jsp:include ?

    JohnnyTheHun wrote:
    - it is more resource consuming isn't it?
    - I cannot access variables I declared in myFirstPage.jsp
    - a can only pass objects to myFirstPartX.jsp and myNextPartY.jsp via the request.setAttribute1. compare to static include, dynamic will more consuming.
    2. if you need to pass string type information you can use jsp:param
    <jsp:include page="x.jsp">
       <jsp:param name="param1" value="value1"/>
       <jsp:param name="param2" value="value2"/>
    </jsp:include>
    <jsp:include page="y.jsp">
       <jsp:param name="param1" value="value1"/>
       <jsp:param name="param2" value="value2"/>
    </jsp:include>
    ...3. for object type information & continous sharing information(main.jsp > x.jsp > main.jsp > y.jsp > main.jsp), u can use request attribute. request attribute is designed for foward & include purpose.
    Edited by: j_shadinata on Feb 5, 2008 10:37 PM

  • Included JSPs not displaying anything

    Hi there
    I'm using the JSP directive to include a small JSP into the main one, using
    <jsp:include page="/Summary.jsp">
    Everything was working fine until I did a change in the Summary.jsp and the included page just stopped generating the HTML. I have a feeling that it is a compilation error, but I just don't get anything in the screen or in the console window for catalina.
    I tried using the <%@ page errorPage="/DisplayException.jsp"%> in the included jsp (Summary.jsp) but the redirection does not happen at all.
    Do I have to turn some kind of flag in Tomcat to see the errors (either compilation or runtime) that happen in the included JSPs?
    I'm using Tomcat 5.0.27 and JDK 1.5 running on Windows.
    Thanks in advance for your time and help
    Leo.

    The problem is that you are getting an error after
    the response is already committed (HTML is already
    written to the client machine). That means that the
    server can not redirect to the error page.
    Your option are to make sure that you do not flush
    the output buffer when you do the include:
    <jsp:include page="..." flush="false"/>
    and make sure that the page that is doing the include
    has a big enough buffer:
    <%@page buffer="20kb" %> (at the top of the page)
    Setting this high enough should make sure that your
    response is not committed before your error occurs,
    and so you should get redirected to the error page.
    The higher it is set, though, the more memory your
    r server will eat up, so remember to turn it back
    down when debugging is done.Hi Steve
    I did that and I could finally see the exception. Thanks a lot for your help
    Leo.

  • Debugging JSP includes

    We are having a debate on what type of jsp includes to use.
    One option is the static include:
    <%@ include file="testinclude.jsp" %>
    The other the dynamic include
    <jsp:include page="testinclude.jsp" flush="true" />
    A major stumbling block to using the former is that we can not seem to debug using it - a breakpoint set at that line appears to be ignored, and any breakpoints within the include itself also appear to be ignored. Why is that?
    Also, are there opinions on the pros and cons between these two methods?
    Thanks,
    Amy Schmieder
    Rentals.com

    Hi Amy,
    The difference between the two tags is that <%@ include> (the "include directive") is processed at compile time, and <jsp:include> (the "JSP include tag") is processed at runtime.
    A JSP is compiled into a Java servlet. When the compiler sees the include directive, it finds the relevant code, compiles it, and drops it straight in. A breakpoint on the directive is never reached because the directive doesn't exist in the compiled version at all (it's been replaced with the included code), and breakpoints in the included code are forgotten when the code is inserted (since they're not stored in the code itself).
    The jsp include tag, on the other hand, functions sort of like a method call to the included code. It's invoked at runtime.
    Advantages and disadvantages:
    On repeat hits, the include directive is faster, since it only needs to be processed once, at compile time.
    However, for just this reason, it's more limited. The jsp include tag can be dynamic--you can programmatically figure out, within your JSP, what you want to include (or, say, what parameters you want to pass the included page). An include directive won't let you do that--information about what exactly will be included must be present at compile time.
    So, for example,
    <jsp:include page="<%= includePage %>" flush ="ture"/>
    is perfectly legal, but
    <%@ include file="<%= includePage %>" %>
    isn't.
    Hope this helps,
    Avrom
    null

  • Repeating parameter names in jsp:include

    Hi,
    I have this jsp code fragment:
    <div>
    <jsp:include page="fragment_1.jsp">
    <jsp:param name="param" value="hello world!"/>
    </jsp:include>
    <jsp:include page="fragment_2.jsp">
    <jsp:param name="param" value="good morning!"/>
    </jsp:include>
    </div>
    When this code executes, the value for param, as the fragment_2 is included, is "hello world!" and not "good morning!".
    How can I use the same name for a param in fragment_2 ?
    Pietro

    The problem is that nothing in the servlet specifications prohibits a requests from having more that one parameter with the same name. It looks that when you set a parameter with the jsp:param tag that it is appending another parameter with that name.

  • Jsp:include an html file in a subdir

    I have the following directory structure and files
    $CONTEXT/articles.jsp
    $CONTEXT/articles/article1.html
    $CONTEXT/articles/images/image01.gif
    When I browse to
    http://$SERVER/$CONTEXT/articles/article1.html
    the article and its image display fine. The file article1.html references the image via an href to "images/image01.gif".
    However, when I try to access the article from articles.jsp via a <jsp:include page="articles/article1.html" flush="true"/>, the article1.html can't find its image. Obviously this is a problem with the relative path to the image.
    I want to be able to correctly view article1.html from directly browsing it and from including it from articles.jsp. How can I include the article1.html from articles.jsp and somehow allow article1.html to find its images? Is this possible?
    Best regards and thanks,
    John

    I have just tried what you say doesn't work, but I have no problem getting it to work. You may want to check your syntax.
    My directory structure is as follows
    SERVERNAME/CONTENT/jspinclude.jsp
    SERVERNAME/CONTENT/inc/inc.html
    SERVERNAME/CONTENT/inc/images/myimage.gif
    my jsp file looks like this:
    <HTML>
    <HEAD>
    <TITLE>Untitled Document</TITLE>
    <META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </HEAD>
    <BODY bgcolor="#FFFFFF" text="#000000">
    This is a test of a jsp.include
    <jsp:include page="inc/inc.html" flush="true" />
    </BODY>
    </HTML>
    my html file looks like this
    <HTML>
    <HEAD>
    <TITLE>Untitled Document</TITLE>
    <META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </HEAD>
    <BODY bgcolor="#FFFFFF" text="#000000">
    <P>This is some sample text</P>
    <P><IMG src="images/myimage.gif"> </P>
    </BODY>
    </HTML>
    This seems to work fine. Perhaps the problem exists somewhere else.
    Rob

  • Problems with Tomcat 4.0 and jdk 1.3.1 (jsp:include) Help Gurus...

    Im running examples of the include:
    <jsp:include page="xxx.jsp" flush="true">
    and received error:
    org.apache.jasper.JasperException: No se puede compilar la clase para JSP
    An error occurred at line: 17 in the jsp file: /jsp/include/include.jsp
    Generated servlet error:
    /Programas/Tomcat4/work/localhost/examples/jsp/include/include$jsp.java:79: Method include(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.String, javax.servlet.jsp.JspWriter, boolean) not found in class org.apache.jasper.runtime.JspRuntimeLibrary.
    JspRuntimeLibrary.include(request, response, "/jsp/include/foo.html" + jspxqStr, out, true);
    ^
    Please Help me Im running this equal with:
    <%@ include file="xxx.jsp" %>
    and runnig fine....

    The two means of including files are different in their approach.
    Using <jsp:include .../> compilation of the included jsp is done at run -time not during compilation.
    Using <%@ include .../> compiles at compile time.
    Looking at the error it seems that the method JspRuntimeLibrary.include is not being found which suggests that you may have a classpath problem. Check that there is not a servlet.jar in the classpath that is from a earlier spec than the one provided with Tomcat.
    Dave

  • SunOne Websever 5 sp 5 dynamic jsp:include

    Hi,
    I'm just trying to migrate from another webserver to SunOne.
    I have a number of pages that rely on dynamic JSP includes.
    IE
    <jsp:include page="<%= someString %>" flush="true">
    All pages which use this fail to compile and I get a server error (no errors show up in the logs).
    While using a static value (the same value) works fine.
    <jsp:include page="somevalue" flush="true">
    Has anyone has this problem ? has this functionality been discontinued ?
    regs
    Michael

    Hi,
    That page refers to the JSP Spec. version 1.1 which is used in WebServer 6.0.
    It is documented in the Release Notes for WebServer 6.0 that jsp:include throws an exception when used with the POST method. Is this what you are experiencing?
    http://docs.sun.com/source/816-5695-10/rn60sp2.html
    Problem 556917. JSP: <jsp:inlcude page="*.html" flush="true" /> Throws Exception If Using With POST Method.
    Which version of webserver are you using?? Your subject line refers to "Websever 5 sp 5" but do you mean Webserver 6.0sp5 or WebServer 6.1sp5??
    WebServer 6.1sp5 uses JSP Spec. version 1.2, so the page that you were referring to is not relevant if you are using this version of WebServer.
    Please note that JSP Specs can be downloaded from:
    http://java.sun.com/products/jsp/reference/api/index.html
    Let us know exactly which version of WebServer you are using :)

  • 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

Maybe you are looking for