Include a jsp in a servlet

Hi,
i have to include a jsp page containing the menu in a servlet that creates a pdf:
         response.setContentType(CONTENT_TYPE_HTML);
         PrintWriter out = response.getWriter();
         out.write("<%@include file=\"../../include/menuoperation.jsp\"%>");
        response.setContentType(CONTENT_TYPE_PDF);
        PdfWriter.getInstance( document, buffer );i get this error: java.lang.IllegalStateException: getWriter() has already been called for this response
Is there a way to include this jsp page without using out.write()?

Sorry for the mess. I'm reposting it...
Hi,
i have to include a jsp page containing the menu in a servlet that creates a pdf:
           response.setContentType(CONTENT_TYPE_HTML);
           PrintWriter out = response.getWriter();
           out.write("<%@include file=\"../../include/menuoperation.jsp\"%");  
           response.setContentType(CONTENT_TYPE_PDF);
          //... some code that creates pdf
          PdfWriter.getInstance( document, buffer ); i get this error: java.lang.IllegalStateException: getWriter() has already been called for this response
Is there a way to include this jsp page without using out.write()?

Similar Messages

  • How can i include a jsp file in servlet?

    hi
    i generate a dynamic page from servlet.
    i need to include a jsp file in same servlet.
    i try like this --
    out.println("<HTML>");
    out.println("<HEAD><TITLE>First</TITLE></HEAD>");
    out.println("<BODY>");
    out.println("<%@ include file=\"abc.jsp\">");
    out.println("<FORM>");
    out.println("</FORM>");
    out.println("</BODY>");
    out.println("</HTML>");

    Replace your line with
    RequestDispatcher rd = request.getRequestDispatcher("abc.jsp");
    rd.include(request, response);

  • How to include a jsp file in servlets and javabeans

    Hi to all..I have a jsp file which contains some database connections and I would like to include in that file in my servlets and javabeans.What coding can i use?Can show me sample coding.

    Hi to all..I have created a javabean storing the
    database connections. How do i include and call that
    bean in my servlet and javabeans?Can pls show me some
    sample coding?I am new to servlets and beans.The same way you do with normal Java Classes. If you are new to Java, I suggest you go to http://java.sun.com/docs/books/tutorial/index.html and look through the first couple of tutorials.
    As a note, it is best to put all your objects into packages, especially if you use JDK 1.4 or higher.

  • Multiple Includes in JSP

              Hi,
              I'm getting a parsing exception when I try to include multiple jsps in the one
              jsp page. Any help would be greatly appreciated!
              The jsp code causing the error is:
                             <%@ include file="mbrDspProfileTravellerInfoPersonal.jsp" %>
                             <%@ include file="mbrDspProfileTravellerInfoAirPref.jsp " %>
                             <%@ include file="mbrDspProfileTravellerInfoCarPref.jsp " %>
                             <%@ include file="mbrDspProfileTravellerInfoHotelPref.jsp " %>
              and the error in the weblogic.log is:
              <16-Jan-02 09:25:00 GMT> <Error> <HTTP> <[WebAppServletContext(8046543,DefaultWebApp,/DefaultWebApp)]
              Root cause of ServletException
              weblogic.utils.ParsingException: nested TokenStreamException: antlr.TokenStreamException:
              Could not include mbrDspProfileTravellerInfoAirPref.jsp
                   at weblogic.servlet.jsp.JspLexer.parse(JspLexer.java:1017)
                   at weblogic.servlet.jsp.JspParser.doit(JspParser.java:78)
                   at weblogic.servlet.jsp.JspParser.parse(JspParser.java:181)
                   at weblogic.servlet.jsp.Jsp2Java.outputs(Jsp2Java.java:119)
                   at weblogic.utils.compiler.CodeGenerator.generate(CodeGenerator.java:255)
                   at weblogic.servlet.jsp.JspStub.compilePage(JspStub.java:327)
                   at weblogic.servlet.jsp.JspStub.prepareServlet(JspStub.java:189)
                   at weblogic.servlet.jsp.JspStub.prepareServlet(JspStub.java:154)
                   at weblogic.servlet.internal.ServletStubImpl.getServlet(ServletStubImpl.java:368)
                   at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:242)
                   at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:304)
                   at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:200)
                   at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:2456)
                   at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2039)
                   at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:139)
                   at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
              

              Thank you so much!!!
              Maeve
              "Michael Reiche" <[email protected]> wrote:
              >Remove the space between the 'p' and the closing quote.
              >
              >Mike
              >
              >
              >"Maeve Loughnane" <[email protected]> wrote in message
              >news:[email protected]...
              >>
              >> Hi,
              >> I'm getting a parsing exception when I try to include multiple jsps
              >in the
              >one
              >> jsp page. Any help would be greatly appreciated!
              >>
              >> The jsp code causing the error is:
              >>
              >> <%@ include file="mbrDspProfileTravellerInfoPersonal.jsp" %>
              >> <%@ include file="mbrDspProfileTravellerInfoAirPref.jsp " %>
              >> <%@ include file="mbrDspProfileTravellerInfoCarPref.jsp " %>
              >> <%@ include file="mbrDspProfileTravellerInfoHotelPref.jsp " %>
              >>
              >> and the error in the weblogic.log is:
              >>
              >>
              >>
              >> <16-Jan-02 09:25:00 GMT> <Error> <HTTP>
              ><[WebAppServletContext(8046543,DefaultWebApp,/DefaultWebApp)]
              >> Root cause of ServletException
              >> weblogic.utils.ParsingException: nested TokenStreamException:
              >antlr.TokenStreamException:
              >> Could not include mbrDspProfileTravellerInfoAirPref.jsp
              >> at weblogic.servlet.jsp.JspLexer.parse(JspLexer.java:1017)
              >> at weblogic.servlet.jsp.JspParser.doit(JspParser.java:78)
              >> at weblogic.servlet.jsp.JspParser.parse(JspParser.java:181)
              >> at weblogic.servlet.jsp.Jsp2Java.outputs(Jsp2Java.java:119)
              >> at weblogic.utils.compiler.CodeGenerator.generate(CodeGenerator.java:255)
              >> at weblogic.servlet.jsp.JspStub.compilePage(JspStub.java:327)
              >> at weblogic.servlet.jsp.JspStub.prepareServlet(JspStub.java:189)
              >> at weblogic.servlet.jsp.JspStub.prepareServlet(JspStub.java:154)
              >> at
              >weblogic.servlet.internal.ServletStubImpl.getServlet(ServletStubImpl.java:36
              >8)
              >> at
              >weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java
              >:242)
              >> at
              >weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java
              >:304)
              >> at
              >weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java
              >:200)
              >> at
              >weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletCo
              >ntext.java:2456)
              >> at
              >weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java
              >:2039)
              >> at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:139)
              >> at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
              >
              >
              

  • Friends..how can i include a jsp page in a servlet

    like i want to use like
    if(conditionl)
    out.println(" welcome");
    //////// here i want to include some jsp page /////
    I tried with...
    <% @include %> but its not working
    Thanks in advance

    I tried with...
    <% @include %> but its not working
    Thanks in advanceThat only woks for JSP Pages.
    You have to call the include method of the RequestDispatcher
    if(conditionl)
      out.println(" welcome");
      getRequestDispachter("/myJSPDir/my.jsp").include(request, response);
    }

  • How to include a jsp page in another jsp jsp page

    hi,
    i m trying to include a jsp page name "header.jsp" into one jsp page name"selectattribute.jsp" i m using these commands in "selectattribute.jsp"
    <%@include file "header.jsp"%> bcz both these jsp page are C:\program files\tomcat 4.0\webapps\examples\jsp\Poject\
    but the problem is that , i m invoking this jsp page "selectattribute.jsp" from a servlet reportcontroller.java using REQUEST DISPATCHER.
    the servlet is in
    C:\Program files\tomcat 4.0\webapps\examples\WEB-INF\classes\Project\
    i want to know how to include some other jsp page in a jsp page and how to invoke applet from jsp page when that particular jsp page is being invoked by servlet.
    plz help
    manish

    use this for including in your selectattribute.jsp
    <jsp:include page="header.jsp" flush="true"/>
    I never tried calling an applet. I think you can write the code for calling the applet in a javabean method and call the method in the jsp

  • Using a real file path to include a JSP using RequestDispatcher

    Hi,
    I am trying to figure out how to use RequestDispatcher inside a servlet to include a jsp page using a real file path instead of a context path. So for example I would want to do something like...
    RequestDispatcher rd = this.getServletContext().getRequestDispatcher("c:/tomcat/conf/think.jsp");
    Is this possible? tomcat is complaining that the path does not start with a "/"
    From a higher level I am trying to setup a solution where all of my web applications can share a set of global jsp pages and other resources. I know the easiest solution would be to put everything into one web application but this does not make sense in my situation because I have differnet web applications for different companies on the same server. Any help would be greatly appreciated. - krebsnet

    First of all...
    My test environment is Tomcat 4.1.24 and it runs on port 80 as my webserver as well.
    I can place the .jsp (or .html) in the shared folder. Not in the lib or class folders but right in the shared folder. I can then call it from multiple contexts without using the context path. Just tested it a minute ago. For example I have test.jsp in the shared folder and loaded it from two separate contexts (one named /demo and one named /inetapps) by calling Load test. It loaded in both of them and neither contain a test.jsp file.

  • How can I include a file in a servlet?

    I need to include a header file in htm format and a footer as well. My question here is, is it possible to include these files when a servlet is executed? like in the cases of the jsp web apps, with the <%@include file = "header.htm"%> tag... please let me know and thanks in advance.
    Regards

    Use RequestDispatcher.include:
    RequestDispatcher rd =
    = this.getServletContext().getRequestDispatcher(url);
    try { rd.include(request, response); }
    catch (Exception e) { "Error : Dispatch includeError
    : " + e); }Where url is the relative url of the HTML file.Hi, thanks for your answer, I still having a problem there, I used the RequestDispatcher.Include but it didn't show the file this is the code I'm trying to use:
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    OutputStream out = response.getOutputStream();
    RequestDispatcher rd = this.getServletContext().getRequestDispatcher("/form.htm");
    try {
    rd.include(request, response);
    catch (Exception e)
    System.out.println("Error : Dispatch includeError : " + e);
    try {
    IntervalCategoryDataset dataset = createGanttDataset();
    System.out.println("Total Categories: " + dataset.getCategoryCount());
    System.out.println("Total series: " + dataset.getSeriesCount());
         JFreeChart chart = ChartFactory.createGanttChart("Activities for F3319G1", "Activity", "Date", dataset, true);
    response.setContentType("image/png");
         ChartUtilities.writeChartAsPNG(out, chart, 800, 600);
    catch (Exception e) {
    e.printStackTrace();
    System.err.println(e.toString());
    finally {
    out.close();
    This servlet gets an image.. so the ContentType is set to "image/png" I don't know if this is causing the problem in such case what would I need to include an html or htm file in this kind of servlet? thanks in advance.
    Regards

  • Include a jsp in another

    I wanr to include a jsp into another, but dinamically. I have a file named Inicio.jsp. This file has a link that calls the servlet "ServletMenu". This servlet decides which jsp page to load. But I want to load "inside" the Inicio.jsp.
    Here a send some code
    Inicio.jsp: shows a menu
    <tr>
    <td>Menu 1</td>
    </tr>
    ServletMenu
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    response.setContentType(CONTENT_TYPE);
    String operacion = (String)request.getParameter("operacion");
    if(operacion.equalsIgnoreCase("menu1")) {
    RequestDispatcher dispatcher = this.getServletContext().getRequestDispatcher("/WebModulo1/Menu1");
    dispatcher.forward(request, response);
    Menu1 contains a form
    The page given by the servlet should show everything that is shown in Inicio.jsp and in the middle of the page should be the content of the Menu1.jsp.
    Am I clear? The idea is mantain a fix menu and load only dynamic content in the middle of the page.
    hope you can help

    I have the code working but ServletMenu only loads the Menu1.jsp and that is not what I want.
    I' m developing an Intranet site. Depending on the user that is logged, the menu that is shown, because not all users have access to all the system tasks.
    I thought of having the pages containing the menu shown to the user done statically and in the middle of that statical page load the content of a dynamic page.
    For example, suppose I have in the server the pages Inicio.jsp, that shows the menu, and Menu1.jsp that shows the same things that Inicio.jsp (but the link to menu1should not exit) and whatever is loaded when the user clicks in the link menu1 of the Inicio.jsp page. The "whatever is loadded" will be another .jsp page, that should be inside Menu1.jsp.
    Hope I'm clearer this time
    Thanks

  • Include directive to include a JSP file from a JAR file

    I have an Eclipse project in which I have placed a JSP file in the package structure with the rest of my code. This is in fact only a code snippet page, not a full blown JSP file.
    I have a second project that is a Dynamic Web Project in Eclipse that incorporates the first project as a JAR in the /WEB-INF/lib directory.
    In this project I have a JSP file and I want to include the JSP file embedded in that JAR file.
    How do I do that?
    I'm thinking the only real solution is to rewrite the snippet portion as a custom tag.

    The JSP fragment page in question is actually a HTML form page. It is a form to be used specifically by a particular servlet. That is why they are "bundled" together in the same project, in the same package structure.
    I have multiple web applications that I want to include that form/servlet, so it gets added to these projects in the /WEB-INF/lib folder as a JAR library. But I don't want to recreate the form over and over again for each application. It would be nice if I could write a JSP page that wraps the fragment using an include directive to bring that fragment into the new page.
    So to do that with any other fragment I would write:
    <%@ include file="/WEB-INF/jsp/SOME_FORM.jsp" %>
    which works great if my fragment page is in the /WEB-INF/jsp subfolder. But if I want to access the JSP fragment as it is bundled in a JAR file, this:
    <%@ include file="/WEB-INF/lib/FORM.jar/SOME_FORM.jsp" %>
    doesn't work so good. It's just all wrong.
    I was wondering how I could just write one include statement to get what I need. There are work-arounds galore, but I thought if I could get this working it would be the simplest solution overall.

  • Can Request Dispatcher include 2 Jsp's ??

    HI ...
    can Request Dispatcher include 2 Jsp's.....in which
    second Jsp is accessing some parameters from First Jsp....
    From my point of view , both jsp's are get compiled seperately hence
    2nd Jsp is not getting parameters from 1st Jsp..
    Any other way to solve this problem....???
    rdTop = sc.getRequestDispatcher("/Reports/top.jsp");
    rdTop.include(req,res);
    rd1 = sc.getRequestDispatcher("/Reports/MenuTrail.jsp");
    rd1.include(req,res);
    Thanks

    No Actually ,i am using include becoz Top .jsp includes our menu,& menu trail also contains our menu...i am displaying both Jsp's thru
    servlet hence i have used Include.....
    Thanks

  • Return JSP page with Servlet

    I know this is a simple problem. I just can't get it working. I am currently trying RequestDispatcher, but it won't work.
    My servlet address normally looks like this: /servlet/myServlet?template=Homepage&channel=HP
    The servlet goes into the database and pulls out the address of the jsp corresponding to "Homepage". It then should display this template.
    When I use RequestDispatcher.include(....); it cant find "/template.jsp". can anybody tell me where this template should be placed. i have put it on the root and in with the servlet and the server still does not find it.
    Thank You
    Mossy

    your template.jsp should be located in
    /<your application directory>/template.jsp
    Then you can do something like this:
    RequestDispatcher dispatcher = request.getRequestDispatcher();
    dispatcher.include("/template.jsp");

  • Retrieve values from a table of a JSP page in Servlet.

    Hello all,
    I am new in JSP servlet world, I want to create a grid on JSP page using Servlet.
    Suppose i have some records in a JSP page and This JSP page will display these records in a tabular form. And, on a button click that table data should be
    accessible in servlet,
    Now, How can i traverse among all the rows of that table of JSP page in servlet. or How can i retrieve a specific cell record of that table of JSP page in servlet.
    Can anyone please answer this.
    Thank you and regards.

    Hi,
    Create in your HTML form inputs with the same name i.e.:
    <input name="a[]" value="2" >
    <input name="a[]" value="9" >
    In your jsp page use :
    String Values[] = request.getParameterValues("a[]") ;
    This will give you a string array of two elements.
    for (int x = 0; x < Values.length; x++)
        System.out.println(Values[x]) ;
    }Will print :
    2
    9
    Hope this helps.
    Bill Moo

  • Urgent....How can i redirect to my jsp page from servlet in init() method..

    How can i redirect to my jsp page from servlet in init() method..Becoz that servlet is calling while server startsup..so im writing some piece of code in init() method..after that i want to redirect to some jsp page ...is it possible?
    using RequestDispatcher..its not possible..becoz
    RequestDispatcher rd = sc.getRequestDispatcher("goto.jsp");
    rd.foward(req,res);
    Here the request and response are null objects..
    So mi question can frame as how can i get request/response in servlet's init method()..

    Hi guys
    did any one get a solution for this issue. calling a jsp in the startup of the servlet, i mean in the startup servlet. I do have a same req like i need to call a JSP which does some data reterival and calculations and i am putting the results in the cache. so in the jsp there in no output of HTML. when i use the URLConnection i am getting a error as below.
    java.net.SocketException: Unexpected end of file from server
    at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:707)
    at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:612)
    at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:705)
    at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:612)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLCon
    nection.java:519)
    at com.toysrus.fns.alphablox.Startup.callJSP(Unknown Source)
    at com.toysrus.fns.alphablox.Startup.init(Unknown Source)
    at org.apache.tomcat.core.ServletWrapper.doInit(ServletWrapper.java:317)
    so plz do let me know how to call a jsp in the start up of a servlet.
    Thanks
    Vidya

  • Problem with JSP and Java Servlet Web Application....

    Hi every body....
    I av developed a web based application with java (jsp and Java Servlets)....
    that was working fine on Lane and Local Host....
    But when i upload on internet with unix package my servlets and Java Beans are not working .....
    also not access database which i developed on My Sql....
    M using cpanel support on web server
    Plz gave me solution...
    Thanx looking forward Adnan

    You need to elaborate "not working" in developer's perspective instead of in user's perspective.

Maybe you are looking for

  • Upgrade from 10.2 to Tiger 10.4.11

    I don't want to upgrade to Leopard. I want Tiger 10.4.11 to run on my PowerBook G4 17inch (running on 10.2)... (This computer is not on line.) Is Tiger 10.4.11 still on the market to purchase? Can I take my PB G4 into an Apple store and have Tiger 10

  • Single report showing stock and sale prices

    Dear SD Wizards. Am seeking to know if any standard report exists which would show me a the existing stock alongwith the valid selling price maintained for the item. I do understand it's from two different areas and such instances are best through de

  • In PS Module, for setting up TECO status

    Hello, I should be able to set the status to TECO(technically completed) on an object (like WBS, Network, Activity) only when all the activities (in the relevant sub-tree of hierarchy) are "finally confirmed". I tried to put some code in BADI 'WORKOR

  • Having problem with cubase le 6

    i have cubase le 6 on my mac and the software comes up and look ok but i can not click on anything but i can use the up and down arrows and all so the enter key but i can not use the mouse plaes help

  • Anyone order later on the 3rd and still no shipping info?

    We ordered later on the 3rd and still haven't received any shipping info - and now when we track the order status it's giving an expected ship date of the 18th, like all of the orders placed today. Anyone else on the preorder not get their phones yet