How to Buffer JSP Output Inside A Servlet

Hello, we are trying to Process a JSP page inside a servlet and then do more processing and finnaly add the JSP output to the response output stream. I know there is a RequestDispatcher that lets you include a JSP page. However as far as I know all you can do with the RequestDispatcher is either include the JSP (which does not buffer it but simply adds it to the output stream) or forward to the JSP page. Any ideas? Thanks, - dk

http://forum.java.sun.com/thread.jsp?forum=33&thread=377214

Similar Messages

  • How to format html output of a servlet

    Hello.
    My servlet/JSP is processed by custom tags and XSL Translation.
    After all its HTML output looks not formatted.
    How to format it?
    It is possible in a standard way (using a web.xml'd directive)?
    What roughly I want:
    <html>
      <body>
      <body>
    <html>

    I'd try
    indent="yes" in your XSLT's<xsl:output .../>element.
    Hope this helps,
    -Scott

  • How to Save JSP output

    Hi all,
    I am new to JSP and I am developing simple application in NetBeans. I got the proper output of the application now I want a button or a link, either would be fine, to save my output in local machine in MS word document or in pdf. So any hint how to archive this using JSP or servlet. Please help me out in this situation. Thanks in advanced.

    Uh, just in the classpath :) Netbeans call it the build path. But you know, in a standard webapplication structure, the WEB-INF/lib folder, which is by default covered by the webapp's classpath, is the place for 3rd party webapp related JAR files.
    To hook on evnafets' reply, yes, once you have got the InputStream containing the JSP content, you've the freedom to do anything with it. Parsing into a HTML DOM tree to extract the data from it, converting HTML to PDF using for example iText, generating MS Word document using for example Apache POI.

  • How does a JSP page send data to a servlet?

    I know, elementary school question, but I can't seem to do it no matter what I tried to do. Here is my code:
           URL url = new URL("http://" + ChatGlobals.SERVER_NAME + "/" +
                    ChatGlobals.SERVLET_PATH + "/ppowell.ChatServlet?message=" +
                    URLEncoder.encode("/a " + cookieArray.getValue())
    out.println("<P>" + url.toString());
    HttpURLConnection conn = (HttpURLConnection)url.openConnection();
    conn.setDoInput(true);     // NOT REALLY INTERESTED IN INPUT BUT MUST BE TRUE
    conn.setDoOutput(false);     // NO OUTPUT
    conn.setUseCaches(false);
    conn.setDefaultUseCaches(false);
    conn.setRequestProperty("Content-type", "text/plain");
         * Do servlet connection to retrieve from ChatServlet URL instance
         * by instantiating an InputStreamReader object
         * @see ChatServlet
    BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
    String stuff = null;
    stuff = in.readLine();
    out.print(stuff);
    in.close();
    in = null;
    conn = null;
    Upon running this code my page just locks up.. URL: http://www.myjavaserver.com/~ppowell/chat.jsp
    But if I call the servlet directly:
    http://www.myjavaserver.com/servlet/ppowell.ChatServlet?message=/a+Phil
    Everything works perfectly, no lockups, no errors, the log and txt files are created. So if my browser calls the servlet everything is ok, but my JSP script in the same directory as my servlet is the one that needs to call the servlet.
    How then does a JSP send data to a servlet?
    Please help, I've been searching in books and online resources for days now with absolutely no apparent luck to do it.
    Thanx
    Phil

    It's correct that a JSP is compiled to a servlet. All HTTP servlets receive requests and send responses via HTTP, of course.
    But this JSP is making a URL connection to a servlet and sending data.
    Are you sure that the URL your JSP creates is identical to the one that works in your browser? Have you printed it out to stdout to verify that it's true? (Code inspection and "it looks right" doesn't count.)
    Why are you doing it this way? It's common to have a JSP send to a servlet, but the usual way of doing it is to put an HTML form in the JSP, including an HTML <input type="submit">, and POSTing the form data to a servlet URL. Why aren't you doing that? - MOD

  • Can't see my Servlet/JSP outputs

    {color:#0000ff}Hello there Java gurus,
    I'm really excited about Java but there seems to be something i'm missing out that is slowing me down. I understand the logic behind the Servlet and JSP technologies - having context root in the webapps subdirectory of the Apache Tomcat, placing other directories like servlets, WEB-INF, classes etc in their respective places and copying .class, .xml, and .html into the proper directory of webapps subdirectories- but still I can't execute properly to view the outputs of even the simplest Servlet and JSP codes.
    When I tried compiling my Servlet Java file to produce a .class file, it gave an error of "javax.servlet does not exist". What can I do again to make me execute my Servlets, because there's truely no javax.servlet in the Java subdirectory of my Program Files.
    Thanks in advance for making this guy smile.
    ***Smiles***{color}

    Ednut wrote:
    Thanks cutton_m for the response, but if you can be clearer on how to get the .jar files or any other file that'd help, i'd be happier. My jakarta-tomcat-5.0.25is successfully installed, and I really don't understand what u mean by j2ee libraries coming with the tomcat's container.
    You need the jars in your classpath.
    The jars came with the J2EE container - in your case tomcat.
    Just what should I do to get the output of my Servlets/JSP codes viewable?Get to build first would be a start.

  • How to get multiple selections from jsp page in my servlet

    Hello Everyone,
    I've a list that allows users to make multiple selections.
    <select name=location multiple="multiple">
        <option>
             All
        </option>
        <option>
             Hyd
        </option>
        <option>
             Dub
        </option>
        <option>
             Mtv
        </option>
      </select>I want to get the selections made by user in jsp page from my servlet, selections can be multiple too.
    ArrayList locList = new ArrayList();
    locList = request.getParameter("location");when I do so, I get compilation error as the request returns string type. How do I then get multiple selections made by the user.
    Please let me know.

    For those kind of basic questions it would help a lot if you just gently consult the javadocs and tutorials.
    HttpServletRequest API: [http://java.sun.com/javaee/5/docs/api/javax/servlet/http/HttpServletRequest.html]
    Java EE tutorial part II: [http://java.sun.com/javaee/5/docs/tutorial/doc/]
    Coreservlet tutorials: [http://courses.coreservlets.com/Course-Materials/]

  • How to get an ArrayList Object in servlet from JSP?

    How to get an ArrayList Object in servlet from JSP?
    hi all
    please give the solution for this without using session and application...
    In test1.jsp file
    i am setting values for my setter methods using <jsp:usebean> <jsp:setproperty> tags as shown below.
    After that i am adding the usebean object to array list, then using request.setAttribute("arraylist object")
    ---------Code----------
    <jsp:useBean id="payment" class="com.common.PaymentHandler" scope="request" />
    <jsp:setProperty name="payment" property="strCreditCardNo" param="creditCardNumber" />
    <%-- <jsp:setProperty name="payment" property="iCsc" param="securityCode" /> --%>
    <jsp:setProperty name="payment" property="strDate" param="expirationDate" />
    <jsp:setProperty name="payment" property="strCardType" param="creditCardType" />
    <%--<jsp:setProperty name="payment" property="cDeactivate" param="deactivateBox" />
    <jsp:setProperty name="payment" property="fAmount" param="depositAmt" />
    <jsp:setProperty name="payment" property="fAmount" param="totalAmtDue" /> --%>
    <jsp:useBean id="lis" class="java.util.ArrayList" scope="request">
    <%
    lis.add(payment);
    %>
    </jsp:useBean>
    <%
    request.setAttribute("lis1",lis);
    %>
    -----------Code in JSP-----------------
    In testServlet.java
    i tried to get the arraylist object in servlet using request.getAttribute
    But I unable to get that arrayObject in servlet.....
    So if any one help me out in this, it will be very helpfull to me..
    Thanks in Advance
    Edward

    Hi,
    Im also facing the similar problen
    pls anybody help..
    thax in advance....
    Litty

  • How do i create a single instance of a class inside a servlet ?

    how do i create a single instance of a class inside a servlet ?
    public void doGet(HttpServletRequest request,HttpServletResponseresponse) throws ServletException, IOException {
    // call a class here. this class should create only single instance, //though we know servlet are multithreaded. if, at any time 10 user comes //and access this servlet still there would one and only one instance of //that class.
    How do i make my class ? class is supposed to write some info to text file.

    i have a class MyClass. this class creates a thread.
    i just want to run MyClass only once in my servlet. i am afriad, if there are 10 users access this servlet ,then 10 Myclass instance wouldbe created. i just want to avoid this. i want to make only one instance of this class.
    How do i do ?
    they have this code in the link you provided.
    public class SingletonObject
      private SingletonObject()
        // no code req'd
      public static SingletonObject getSingletonObject()
        if (ref == null)
            // it's ok, we can call this constructor
            ref = new SingletonObject();          
        return ref;
      public Object clone()
         throws CloneNotSupportedException
        throw new CloneNotSupportedException();
        // that'll teach 'em
      private static SingletonObject ref;
    }i see, they are using clone !, i dont need this. do i ? shouldi delete that method ?
    where do i put my thread's run method in this snippet ?

  • How to display the JSP output in the same page....

    im new to JSP..... can anyone tell me how to display the output of a particular JSP page in the same page itself...... if anyone could send a small sample code it will be very useful for me....
    thanks in advance
    regds
    Krish......

    Hi Robert -
    When you say you are writing a template-based Renderer, do you mean that you are creating a custom look and feel and replacing the header Renderer? If so, I'd recommend instead simply creating your own template (not template-based Renderer), and reference your template directly from your uiXML pages where you want to insert the timestamp.
    You'll probably want to write a method data provider which calls System.currentTime(), convert the result to a date, and then use Java's date formatting capabilities (see java.text.format.DateFormat) to produce a user presentable String that you can return from your data provider.
    For more info (and samples) on templates and data binding, see the "Templates and Data Binding" section of the "Includes and Templating in ADF UIX" help topic:
    http://tinyurl.com/5b7bf
    Andy

  • How to execute jsp.servlet program in eclipse with small example

    This is sasidhar,
       How to set classpath pf tomcat to eclipse.
    and how to run jsp and servlets in eclipse 3.o
    thanks&regards
    sasidhar

    HI,
    Try these links
    http://help.sap.com/saphelp_nw04/helpdata/en/64/620a2ae361344abf47462809eb5388/frameset.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/f6/baba3eb645dc61e10000000a114084/frameset.htm

  • How to forward an applet page to servlet/jsp?

    I have an applet in imageMap.jsp file. This applet displays a map. When user enters the page of imageMap.jsp, they will see the map . If user clicks a point of the map, the latitude and longitude of that point should be sent to Search.java servlet and search results should replace the current page.
    My Search.java servlet works well.
    I think I should add mouse event in the applet. I can use MouseEvent.getX() and MouseEvent.getY() in the applet to get latitude and longitude. But I do not know how to go from this applet to servlet. How can I forward applet page to servlet?

    The <jsp:plugin> action is used in pages to generate client specific HTML tags involving download and execution of the applet that is specified in the tag.

  • How do I send E-Mail using Servlet or JSP?

    Hi friends,
    Anybody can you please tell me how do I send an email in Servlet or JSP?
    Do I need any special configuration to check in my server space?
    I am puzzled because after surfing on net, I found that some people sending email with Javamail and Activation API
    and some people sending email using import="sun.net.smtp.SmtpClient";Please give me some simple direction or any working code if possible.
    Thanking u,
    ---Sujoy

    What you need is a working SMTP account to be able to send email, that is accessible from the server. If you have that, simply use JavaMail.

  • How to run JSP/Servlet in AIX?

    how to run JSP/Servlet in AIX?
    I am no ideas about it,
    can anyone tell me?
    what webserver i should use?
    have to install JDK?

    The only successful way that I have been able to run servlets in an AIX environment is with the IBM Http Server (specific version of Apache)/WebSphere combination, with WebSphere as the servlet engine. I have tried (unsuccessfully) to use JRun and Apache in AIX environment, but could never get JRun to function properly.

  • How JSP is faster than Servlets ??????

    can anyone tell me why and how jsp is faster than servlets.
    i want the detailed description of this question.
    thanks in advance..

    Hi simmy1,
    The performance of JSP pages is very close to that of servlets. However, users may experience a perceptible delay when a JSP page is accessed for the very first time. This is because the JSP page undergoes a "translation phase" wherein it is converted into a servlet by the JSP engine. Once this servlet is dynamically compiled and loaded into memory, it follows the servlet life cycle for request processing. Here, the jspInit() method is automatically invoked by the JSP engine upon loading the servlet, followed by the _jspService() method, which is responsible for request processing and replying to the client. Do note that the lifetime of this servlet is non-deterministic - it may be removed from memory at any time by the JSP engine for resource-related reasons. When this happens, the JSP engine automatically invokes the jspDestroy() method allowing the servlet to free any previously allocated resources.
    Subsequent client requests to the JSP page do not result in a repeat of the translation phase as long as the servlet is cached in memory, and are directly handled by the servlet's service() method in a concurrent fashion (i.e. the service() method handles each client request within a seperate thread concurrently.)
    I hope this will help you out.
    Regards,
    TirumalaRao.
    Developer TechnicalSupport,
    Sun Microsystems,India.

  • How to Show the Alerts inside the Form in JSP?

    Hello
    I am having parent form inside that thru one of the links,opening
    a small another JSP. Inside the small another JSP, i am validating
    the Screen and giving alerts. While Validating, the Alerts are coming
    outside the small another JSP and appearing in the Parent Big Page.
    I want the alert to appear in the small Another JSP. What to do?
    Thanks

    When you submit, the whole form is submitted. thats why you are getting alerts like that.
    you can use HTML frames to avoid these. but it is not possible to have frames inside a form. you have to have forms inside a frame. submit that particular frame's form so that only that part will be refreshed with messages/alerts.
    the otherway is paint the screen as it was earlier just change the inner jsp content. its seems you are getting only alerts cos the information is same.
    -sun

Maybe you are looking for

  • Passing values to ABAP/JAVA  webdynpro appl. when workitem invoked from UWL

    Hai, We are using universal worklist for invoking a workitem. The workitme may trigger a ABAP/Java based webdynpro application. I have registered the tasks associated with the workitem in universal worklist. I have few doubts in the integration part,

  • How to add field to standard screen of PNP

    hello masters, tell me one thing: - it is possible to add a field that isn't part of PNP logical database to the standard screen PNP. Could someone help me? regards and thanks in advance Mário

  • ISetup new custom interface using BC4J/java class

    Hi, I am able to create new custom interface using the link :- How to setup an user to be Oracle iSetup Super user ? but I have not seen anything for BC4J filter set, as per oracle iSetup developer guide clearly explains step by step process how to c

  • I don't live in CHINA!!

    I live in Europe, and have had auto-recharge for years. But I needed to change credit card. So I remove the old one and push "Add new payment method", and voila - I am on Skype China, expected to read Chinese and pay in RMB. Anybody met the same stup

  • Adobe Digital Publishing Suite is included in CC subscription

    is this app included in the Creative Cloud subscription?