Possible to redirect JSP output?

Is it possible to redirect the output of a JSP either directly to a printer or directly to a File object? I would like to write a report template using JSP and be able to display it via a browser (so far so good, that's what JSP does) but I'd also like to take the same output that the JSP generates and either print it directly (as in printing many many reports without having to run each one in a browser and click the browser print button) AND to be able to email the report to a client.
Each of these means I need to redirect the output of a JSP. I couldn't find anything in this forum about that. Is this even possible?
Thank you in advance for your answers.

The problem with using a new URLConnection is that the current session is not applied to the JSP page as desired.
For those using Tomcat 4, which implements the Servlet 2.3 spec, this page describes how to replace the output stream of a servlet with your own.
http://www-106.ibm.com/developerworks/java/library/j-tomcat/
The example implements a character replacement mechanism. Using a filter and a wrapper. I modified this example to redirect the output stream to a file, which allowed me to then e-mail the output of a JSP. I did this by only using the wrapper classes.
Here are the relavant excerpts from my code
//Inside the servlet:
//{snip}...
String sFileName = "e:\\temp\\email\\temp.html";
RedirectTextWrapper rTW =
new RedirectTextWrapper(response, sFileName);
gotoPage(sAddress, request, rTW);
//{snip}...
//Supporting classes:
class RedirectTextStream
extends ServletOutputStream {
private OutputStream intStream;
private boolean closed = false;
public RedirectTextStream(String sFileName) {
try{
intStream = new FileOutputStream(sFileName);
}catch(FileNotFoundException e){
e.printStackTrace();
public void write(int i)
throws java.io.IOException {
intStream.write(i);
public void close()
throws java.io.IOException {
if (!closed) {
intStream.close();
closed = true;
public void flush() throws java.io.IOException {
intStream.flush();
class RedirectTextWrapper
extends HttpServletResponseWrapper {
private PrintWriter tpWriter;
private RedirectTextStream tpStream;
public RedirectTextWrapper(ServletResponse inResp,
String sFileName)
throws java.io.IOException {
super((HttpServletResponse) inResp);
tpStream = new RedirectTextStream(sFileName);
tpWriter = new PrintWriter(tpStream);
public ServletOutputStream getOutputStream()
throws java.io.IOException {
return tpStream;
public PrintWriter getWriter()
throws java.io.IOException {
return tpWriter;
}

Similar Messages

  • IS IT POSSIBLE TO REDIRECT THE OUTPUT TO ANOTHER PAGE?

    Hi all,
    Is it possible to redirect the output when I excute my query in iSQL*plus to another predifined html page?
    If yes how do I do this?
    Thanks a mill

    You could do this..just read on..
    It would generate a html page for you...and..so on..!
    In addition to plain text output, the SQL*Plus command-line interface enables you to generate either a complete web page, or HTML output which can be embedded in a web page. You can use SQLPLUS -MARKUP "HTML ON" or SET MARKUP HTML ON SPOOL ON to produce complete HTML pages automatically encapsulated with <HTML> and <BODY> tags.
    By default, data retrieved with MARKUP HTML ON is output in HTML, though you can optionally direct output to the HTML <PRE> tag so that it displays in a web browser exactly as it appears in SQL*Plus. See the SQLPLUS MARKUP Options and the SET MARKUP command for more information about these commands.
    SQLPLUS -MARKUP "HTML ON" is useful when embedding SQL*Plus in program scripts. On starting, it outputs the HTML and BODY tags before executing any commands. All subsequent output is in HTML until SQL*Plus terminates.
    The -SILENT and -RESTRICT command-line options may be effectively used with -MARKUP to suppress the display of SQL*Plus prompt and banner information, and to restrict the use of some commands.
    SET MARKUP HTML ON SPOOL ON generates an HTML page for each subsequently spooled file. The HTML tags in a spool file are closed when SPOOL OFF is executed or SQL*Plus exits.
    You can use SET MARKUP HTML ON SPOOL OFF to generate HTML output suitable for embedding in an existing web page. HTML output generated this way has no <HTML> or <BODY> tags.

  • Redirecting JSP output

    What is the best way to run a jsp in my web application without sending the output to the client? For example, I may want to save the output to a file or send it through a converter to remove the unnecessary leading spaces by sending the output through my own output stream.

    I think you need a servlet filter (I haven't used them before). This link discusses them:
    http://www.onjava.com/pub/a/onjava/2003/11/19/filters.html
    The third page of the link talks about a cache filter which may help you.
    If the link isn't enough, I suggest reading up more on servlet filters..

  • Is it Possible to display the output of the ALV list as POP-UP

    Hi Experts,
                     Is it Possible to display the output of the ALV list as POP-UP, if yes then provide some ideas on it.
    thanking in advance,
    Samad.

    Hi samad, it is possible to display alv list as pop-up by using the FM " REUSE_ALV_POPUP_TO_SELECT"
    try this sample code
    CALL FUNCTION 'REUSE_ALV_POPUP_TO_SELECT'
          EXPORTING
       I_TITLE                       =  P1_TITLE
           I_SELECTION                   = 'X'
           I_ZEBRA                       = 'X'
      I_CHECKBOX_FIELDNAME          =
      I_LINEMARK_FIELDNAME          =
      I_SCROLL_TO_SEL_LINE          = 'X'
            I_TABNAME                     = 'T_VBAP'
           I_STRUCTURE_NAME              =  'T_VBAP'
           IT_FIELDCAT                   =  T_FCAT2
           I_CALLBACK_PROGRAM            = 'ZTEST_ALV_POPUP'
       IMPORTING
           ES_SELFIELD                   = I_SELFIELD
           E_EXIT                        = W_EXIT
          TABLES
            T_OUTTAB                      = T_VBAP.
    i think it will solve your problem
    Regards,
    Vijay

  • How to redirect the output display on Ultra 5 box.

    Hello,
    Good day to you.
    I have issues with redirecting display output to my console server (which is configured with cyclades switch) on a newly installed solaris 10, Ultra 5 box.
    I could access the output display on the monitor when I connect it directly to the serial port. But I also have my parallel port connected to cyclades switch which is primarily being used for accessing multiple servers thro' one single console server.
    When I try to access my ultra 5 box thro' console server, the display not getting redirected over there..I did checked the port from cyclades switch front, it did work well with other machines.
    Looks like some work needs to be done at Ultra 5 box level so that the parallel port can send output signals to the respective port on cyclades switch and consequently to the console server.
    Any thoughts ??
    Thanks.

    Hi,
    Good day to you.
    Apologize for quoting "Parallel" port. It is a in-built 25pin serial connector placed next to regular 15 pin serial port.
    Just to make a point here, this 25 pin serial connector has an external converter attached with other side having RJ45 jack.
    CAT5 cable connected between switch port to this RJ45 jack.
    I did tested this converter with another machine and could able to access the display on my console server. So it seems to be the connectivity from serial port to switch port works fine.
    Adding to that, this ultra 5 box with the current connectivity set up was working fine until I rebuild this machine. I was very well accessing this box thro my console server. There was no changes done except rebuilding the operating system.
    I think some work needs to be done at the ultra 5 box level to get this 25pin serial connector to act.
    Thanks.

  • Is it Possible to upload the output from Oracle reports To Access database

    Hi All,
    Wish you All a Very Happy New Year.
    I have a query.Is it possible to
    upload the output from the Oracle reports
    to the Access database???
    Any suggestions would be appreciated.
    TIA
    sg

    Hi sg,
    Research the DDE option.
    Dynamic Data Exchange (DDE) is a mechanism by which applications can communicate and exchange data in Windows.
    I have imported data into the excel spreadsheet using DDE built in functions. I am sure it can work with MS Acess as well. If not, then you need to create a 2 step process .. reports -> excel -> access.

  • How to redirect standard output/error of a ucb function to matrixx command window

    Is there a way to redirect standard output/error of a ucb function to matrixx command window?
    I know that the recommended way is to use stdwrt or XmathDisplay commands. However, we have some
    libraries that already exists which uses printf calls and I would like to redirect their output
    to the matrixx command window.
    Thanks

    Hi,
    What you need to do is create a printf function that will print the information into a string, then you can use stdwrt to display it in Xmath.
    Then you tell the UCB linking process to compile and link with this version of printf.c
    I am including the printf.c that we used to test the function you needed.
    Hope this helps.
    Attachments:
    printf.c ‏1 KB

  • Help on jsp:output

    I am trying to use the <jsp:output> tag within jdeveloper10.1.2, but it is not included within the tags for JSP in the component pallete, so I keep getting an error. Any idea, pls ?

    jsp:output is a J2EE 1.4 JSP 2.0 tag.
    JDeveloper 10.1.2 provides only the JSP 1.2 tags.
    http://java.sun.com/products/jsp/syntax/1.2/syntaxref12.html
    JDeveloper 10.1.3 supports J2EE 1.4 (JSP 2.0).
    Some of the JSP 2.0 tags are not in the Component Palette.
    jsp:output tag, jsp:invoke and jsp:text tags which are jsp 2.0 tags are not in the Component Palette.
    http://java.sun.com/products/jsp/syntax/1.2/syntaxref12.html

  • Redirect standart output to file

    i want to ask how to redirect standart output to file,
    if i have statement like this System.out.println("hello"); i want hello not print in console but print to file
    thx

    Here is sample code for that:
      static{
        try {
          PrintStream obj_ps = new PrintStream(new FileOutputStream("internal.log"));
          System.setOut(obj_ps);
          System.setErr(obj_ps);
        catch (FileNotFoundException ex) {
          JOptionPane.showMessageDialog(null, "Error creating log file", "Error", JOptionPane.ERROR_MESSAGE);
      }

  • Redirecting cmd output to a JTextArea

    can anyone help me, im curious how can the compilers for java e.g.: Netbeans, JCreator, redirect the command promt output to a JTextArea..
    can anyone guide me on what class to look at??
    thanks a lot

    here is a simple class that redirects the standard output to a file called a.txt. you have to look into the class java.class.System. and other i/o classes
    import java.io.PrintStream;
    public class A {
        public A() {
        public static void main(String[] args) throws Exception {
            PrintStream fileOut = new PrintStream("a.txt");
            System.setOut(fileOut);
            for (int i = 0; i < 10; i++) {
                System.out.println(i);
    }for your case where output goes to a textArea you might wanna use a multithreaded solution. redirect your output to a file as above and use the thread to read the file and paste text into your text area. there is other better solution that directly passes data into the textArea. i'll post it if can find it in my code base.

  • How to redirect CELLCLI output to text file

    Hi,
    I would like to redicrect the output of the cellcli command to a text file .
    For example , how to redirect the output of this command to a text file on /tmp
    CellCLI> list metrichistory where objectType = 'CELL' -
    and name = 'CL_TEMP'Thanks

    cellcli has spooling capabilities similar to sqlplus:
    CellCLI> help spool
      Usage:  SPO[OL] [<filename> [ CRE[ATE] | REP[LACE] | APP[END]] | OFF ]
      Purpose: SPOOL <filename>: Direct the results to the file <filename>.
               SPOOL OFF: Turn off the spooling.
               SPOOL: Check the current spooling status.
      Arguments:
        <filename>: The filename where the results will be output.
      Options:
        [APPEND]: If the filename already exists, the following output will
                  be appended to the file. Without this option, the existing file
                  contents will be replaced.
        [CREATE]: If the filename already exists, an error is reported.
        [REPLACE]: If the filename already exists, the contents will be
                  replaced.  This is the default, when no option is provided.
      Examples:
        spool myfile
        spool myfile append
        spool off
        spoolBut if you are trying to script it, it would be easier to just run it command line:
    # cellcli -e "list metrichistory where objectType = 'CELL' and name = 'CL_TEMP'" > /tmp/CL_TEMP.txtAlso look into dcli which allows you to run cellcli commands on one or more cells from a compute node.
    Good luck.

  • Redirecting XSLT output to multiple files

    Hi,
    I am trying to redirect the output of the XSLT into multiple files using
    <xsl:variable name="filename" select="concat(@id,'.xml')" />
    <redirect:write select="$filename">
    </redirect:write>I dont want to hard-code the directory of the $filename in XSL, I want to set it or resolve it programatically in the java code.
    Can you please tell me if this can be done in someway ?

    Aravinda wrote:
    I dont want to hard-code the directory of the $filename in XSL, I want to set it or resolve it programatically in the java code.
    Can you please tell me if this can be done in someway ?You + setParameter + method of your Transformer in java code to set parameters. like below:
    transformer.setParameter("message1", "This is my message to XSLT from Java Class.");
    transformer.setParameter("message2", "Hello XSLT how are you?");
    . . .You can retrieve above parameters in global parameters/variables(must be as child of xsl:stylesheet element in xslt) defined in xslt like below:
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
         <xsl:param name="message1"></xsl:param>
         <xsl:variable name="message2"></xsl:variable>
         <xsl:template match="/">
              <xsl:value-of select="$message1"/>     // retrieving message1
              <xsl:value-of select="$message2"/>     // retrieving message2
              <xsl:value-of select="concat($message1,$message2)"/>     // performing concat on message1 and message2
         </xsl:template>
    </xsl:stylesheet>*Cheers
    TYPUROHIT*
    (Tejas Purohit)

  • Extra white spaces in JSP output

    Hi,
              My JSPs contain a large use of JSTL and other custom Tags.
              The problem is that the output contains too many new lines and spaces.
              I found out that APACHE Tomcat has a servlet parameter (trimSpaces=true) that solved this problem.
              Does Weblogic (9.1) have something similar ?
              Does JSPC / APPC have a special options that can solve this ?
              please advise,
              Avivi.

    Before diving into this, one thing I would ask you: Why does it matter if there are extra spaces? Did you determine that your primary users are using a slow connection? Before trying to optimize this, make sure that you really have a problem to solve. You might try saving off the currently generated HTML into a test page, and compare it to a similar one with all ignorable spaces removed. If you see no difference in performance, then don't bother doing this.
              Nevertheless, one strategy for reducing empty space in JSP output is to put the ends of the JSP directives and actions on the next line, with no newlines after them.
              For instance, a pair of lines like this:
              <%@page import="foo.bar" %>
              <%@page import="bar.foo" %>
              Would be instead:
              <%@page import="foo.bar"
              %><%@page import="bar.foo"
              %>

  • How to redirect console output while starting server from within IDE

    Hello, i am using Weblogic Workshop IDE. When I start the server, a new cmd shell is launched and the jvm output is displayed in this cmd shell window. How can I redirect this output to show up within the IDE (for instance in the Console view)?
    Problem is that when an error occurs, the cmd window disappears and I cannot tell what the error was.
    Surely there is a way to do this as other IDEs (JBuilder, Rational etc.) allow this.
    Thanks:
    -Sam

    Hi Sam,
    Unfortunately, this feature does not exist in Workshop 9.2
    Regarding your question about redirecting the output, the logs are saved under the domain directory.
    You could also refer to the following section for additional info on redirecting the output to multiple destinations.
    http://e-docs.bea.com/wls/docs90/ConsoleHelp/taskhelp/logging/RedirectJVMOutput.html
    Hope this helps.
    cheers
    Raj

  • IE don't display JSP output. It pop up download dialong and open Dreamwea

    IE don't display JSP output. It pop up download dialong and open Dreamweaver.
    I dont' know why, but when run in Netscape is OK
    Anyone please help.

    Looks like your problem lies by the file associations, i.e. extension of your jsp file (.JSP) is associated in your operating system with DreamWeaver rather than with IE. If you are using Windows you should be able to change file associations, so that all web pages including JSP will be opened in your browser.

Maybe you are looking for

  • Hp Mini 5101 Freezes While Installing Windows....All versions, xp,vista,7,8.....Nothing Takes

    I refurbish companies retired computers as part of my business, part of our agreement is the machines all come blank, they delete partitions and wipe the entire hdd multiple times prior to my getting them, Most are as simple as reinstalling windows a

  • No vendor assigned for Service Procurement

    Hi all, While creating request for External Staff, i am unable to assign vendors for the request. I created service in COMMPR01 and created contract with vendor, but i am unable to see the vendor while creating request and no F4 help to assign vendor

  • SCREEN problem!! / solution for use

    hi Falling object has left my powerbook screen unusable......computer is still working though....Q is there a way to link up a monitor to the laptop for continued use..... without needing ORIGINAL SCREEN TO CONFIGURE? rg

  • Split Code View

    I would like to be able to split (horizontally) code in code view so I can see different sections of code on a long page. Is there a way, keyboard shortcut or extension to do this? Many thanks, Martin

  • "javax.microedition.io.ConnectionNotFoundException: TCP open" Exception

    Dear All, I get "javax.microedition.io.ConnectionNotFoundException: TCP open" exception in J2ME program written by netbean with WTK2.0. I found out the exception got when I submit the URL to internet address (e.g. www.yahoo.com or www.google.com). Ho