Results 1 to 6 of 6

Thread: Include explicitly a jsp page in another

  1. #1
    Join Date
    Nov 2009
    Posts
    42

    Include explicitly a jsp page in another

    I have a jsp page which includes another jsp that currently provides
    Code:
    <%String query="";%>
    <%@include file="/queries/query1.jsp"%>
    <%out.print(query);%>
    with the file query1.jsp
    Code:
    <%query="SELECT * FROM TABLE1";%>
    I now make that power dynamics and include query1.jsp or query2.jsp example. So I tried with <jsp:include
    Code:
    <%
    String query="";
    String nb="1";
    %>
    <jsp:include page="/queries/query<%=nb%>.jsp"></jsp:include>
    <%out.print(query);%>
    but then out.print (query) does not return me the value I put in query1.jsp to the page that was included. How?

  2. #2
    Join Date
    May 2008
    Posts
    2,297

    Re: Include explicitly a jsp page in another

    You do not have to declare the calling page the String query. You declare in query1.jsp. We must see the jsp included as a portion of the jsp appellant. What gives JSP 1:
    Code:
    <%String query= "SELECT * FROM TABLE1" ;%>
    Code:
    <% String nb="1";%>
    <jsp:include page="/queries/query<%=nb%>.jsp"></jsp:include>
    <%=query%>
    Little info if you have several lines of code in a jsp you can simply use <% and%> between the first and last line of Java code

    This can also be interpreted with html example:
    Code:
    <%for(int i=0;i<10;i++){%><b>coucou</b><%}%>
    To display a value in the page you must not do:
    Code:
    <%out.print(query);%>
    but
    Code:
    <%=query%>
    Small question, is that what you show is just an example or you really want to have a jsp/request.

    If its so much to query a table then always include this jsp

  3. #3
    Join Date
    Nov 2009
    Posts
    42

    Re: Include explicitly a jsp page in another

    I tested and if I do not declare query in the calling page I receive an error message:

    type Exception report

    message

    description The server encountered an internal error () that prevented it from fulfilling this request.

    except

    org.apache.jasper.JasperException: Unable to compile class for JSP

    An error occurred at line: 3 in the jsp file: / Test / test.jsp
    Generated servlet error:
    query can not be resolved


    org.apache.jasper.servlet.JspServletWrapper.handleJspException (JspServletWrapper.java: 512)
    org.apache.jasper.servlet.JspServletWrapper.service (JspServletWrapper.java: 377)
    org.apache.jasper.servlet.JspServlet.serviceJspFile (JspServlet.java: 314)
    org.apache.jasper.servlet.JspServlet.service (JspServlet.java: 264)
    javax.servlet.http.HttpServlet.service (HttpServlet.java: 802)


    root cause

    org.apache.jasper.JasperException: Unable to compile class for JSP

    An error occurred at line: 3 in the jsp file: / Test / test.jsp
    Generated servlet error:
    query can not be resolved


    org.apache.jasper.compiler.DefaultErrorHandler.javacError (DefaultErrorHandler.java: 84)
    org.apache.jasper.compiler.ErrorDispatcher.javacError (ErrorDispatcher.java: 328)
    org.apache.jasper.compiler.JDTCompiler.generateClass (JDTCompiler.java: 414)
    org.apache.jasper.compiler.Compiler.compile (Compiler.java: 297)
    org.apache.jasper.compiler.Compiler.compile (Compiler.java: 276)
    org.apache.jasper.compiler.Compiler.compile (Compiler.java: 264)
    org.apache.jasper.JspCompilationContext.compile (JspCompilationContext.java: 563)
    org.apache.jasper.servlet.JspServletWrapper.service (JspServletWrapper.java: 305)
    org.apache.jasper.servlet.JspServlet.serviceJspFile (JspServlet.java: 314)
    org.apache.jasper.servlet.JspServlet.service (JspServlet.java: 264)
    javax.servlet.http.HttpServlet.service (HttpServlet.java: 802)

    note The full stack trace of the root cause of this error is available in the log files of Apache Tomcat/5.5.20.

  4. #4
    Join Date
    May 2008
    Posts
    2,297

    Re: Include explicitly a jsp page in another

    I did not test something dynamic as you propose and I passed by
    Code:
    <%@ include file= "Context.jsp" %>
    And I do not think you could get what you want because a JSP is compiled once and only once I explain if you change the page included the JSP container will not necessarily update in my case it is does not.

    If you change the calling page will update its data as part included. I do not know if this is configurable or not (specific to each application server) and what to me is akin to a sort of cache problem my solution to empty the cache server that contains the compiled jsp (myJSP.class).

    I know if I really answered your question. I suggest you explain what you want to see if we can improve the process/design or find another alternative to your problem.

  5. #5
    Join Date
    Nov 2009
    Posts
    42

    Re: Include explicitly a jsp page in another

    what I want to do is actually a tool extraction csv generic. I therefore have a class that will handle the output based on a SQL query that it would be saved in a file jsp form
    Code:
    <%String query= "select champs from table" ;%>
    the trick is that these jsp files containing requests already exist and are also used to something else and if we change the query in one of these files I am having the same request for my extraction csv so I can not afford having the query in several places so I wanted to do a dynamic include these files in the functions of a parameter

    So something like a file csv.jsp which would include a file query_X (X being the name of the table about 300 tables I think) and after making the request, the conversion functions in field types, and the final output

    I need a same principle for my reporting tool (Crystal Reports)

  6. #6
    Join Date
    May 2008
    Posts
    2,297

    Re: Include explicitly a jsp page in another

    Could not you just use a property file containing all of your queries?
    Code:
    query.1=select * from dual
    query.2=select foofrom dual
    query.3=select * from dual
    ....
    Via a static method gets you the right application at your jsp

    What could meet your need.

Similar Threads

  1. How to include Webpage into your main page without using iFrame
    By Sanju Baba in forum Software Development
    Replies: 4
    Last Post: 20-01-2012, 10:56 AM
  2. Replies: 9
    Last Post: 26-08-2011, 11:44 AM
  3. Replies: 3
    Last Post: 24-07-2011, 08:05 AM
  4. How to use include() in PHP?
    By Emily123 in forum Software Development
    Replies: 6
    Last Post: 06-03-2010, 05:49 AM
  5. Include a page with onclick
    By CodGuru in forum Software Development
    Replies: 3
    Last Post: 08-04-2009, 08:37 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,750,443,549.59532 seconds with 16 queries