Use the RequestDispatcher's include function.
There are several ways to get the RequestDispatcher (slight difference
depending on where u get it from) but the way that I usually do it is:
        request.getRequestDispatcher("fileIWantToInclude.jsp").include(
request, response );
Look for a NullPointerException which will be thrown by the above if the
file does not exist.
-Tim

-----Original Message-----
From: antony [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, November 14, 2001 7:45 PM
To: JSP-INTEREST
Cc: antony
Subject: Re: JSP/SERVLET DESIGN QUESTION


How can I include these "includes" from a servlet?

Cheers

Tony

Chen, Gin wrote:

> Why dont u just put the includes inside the servlet?
>
> -----Original Message-----
> From: Antony Stace [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, November 14, 2001 4:35 AM
> To: [EMAIL PROTECTED]
> Subject: JSP/SERVLET DESIGN QUESTION
>
>
> Hi
>
> I have a question....I want to know if the following is bad design.
>
> I have a servlet, called Simple,  with the following doPost code in it
>
> [snip]
>      public void doPost(HttpServletRequest request,
>                         HttpServletResponse response)
>             throws ServletException, IOException
>      {
>          PrintWriter out = response.getWriter();
>          out.println("Simple.doPost() I am a test printing a line from
> Simple.");
>      }
> [snip]
>
> I call this from a jsp file
>
> ------------------------------
> <HTML>
> <HEAD>
> <meta http-equiv="Content-Type" content="text/html">
> </HEAD>
>
> <BODY>
> <%@ include file="header.jsp" %>
>
> <jsp:include page="/servlet/simple" flush="true"> </jsp:include>
>
> <%@ include file="footer.jsp" %>
> </BODY>
> </HTML>
> ------------------------------
>
> Is this a bad design?
>
> If in the doPost() method in Simple I have a out.close() then the
>
> [snip]
> <%@ include file="footer.jsp" %>
> </BODY>
> </HTML>
> [end of jsp file]
>
> is not included in the output of the jsp page when it is run.  Should
> I use a  custom taglib instead?
> I have a number of pages which I want to have a common header and
> footer, but I want the middle part to be constructed by a servlet.
Whats
> the best way to go about this?
>
>
> Cheers
>
> Tony
>

========================================================================
===
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://archives.java.sun.com/jsp-interest.html
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.jsp
 http://www.jguru.com/faq/index.jsp
 http://www.jspinsider.com

---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.295 / Virus Database: 159 - Release Date: 11/1/01

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.295 / Virus Database: 159 - Release Date: 11/1/01

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://archives.java.sun.com/jsp-interest.html
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.jsp
 http://www.jguru.com/faq/index.jsp
 http://www.jspinsider.com

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://archives.java.sun.com/jsp-interest.html
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.jsp
 http://www.jguru.com/faq/index.jsp
 http://www.jspinsider.com

Reply via email to