How to print console output
Hi, I have a JSP page and I would like to print STDOUT to the page. Is this possible?
I've seen a few methods and none work for me:
BufferedReader reader = new BufferedReader(System.out);
String input = reader.readLine();
out.println(input);*** Error: Type BufferedReader was not found.
FileOutputStream out;
PrintStream ps; // declare a print stream object
try {
// Create a new file output stream
out = new FileOutputStream("myfile.txt");
// Connect print stream to the output stream
ps = new PrintStream(out);
ps.println ("This data is written to a file:");
System.err.println ("Write successfully");
ps.close();
catch (Exception e){
System.err.println ("Error in writing to file");
}*** Error: Duplicate declaration of local variable "out".
*** Error: The type of the left-hand side in this assignment, "javax/servlet/jsp/JspWriter", is not compatible with the type of the right-hand side expression, "java/io/FileOutputStream".
*** Error: No match was found for constructor "PrintStream(javax.servlet.jsp.JspWriter)".
So what's next?
How can I call the console without writing to a file first?
I would like AJAX to show console output in real-time.
Thanks for your help.
The reason I have the script to write to a file is because it's the closest I could find to what I want. Ideally, I would be able to run a script that prints to the console but I want to grab the system.out going to the console and display it on the page.
Basically, I want the page to act as a console but not redirect the output (I want it to still go to the console) and I don't want it in a text file that the page reads.
So for example, the page loads and while that is occurring, the server grabs the console output and prints to the page. Then I run a function on the page that prints to the console and on the refresh, print the updated output. Ideally, I would restrict the output that was relevant to the page's functions and ignore every output to the console but I'm not (trying to be) picky.
So how would that work?
Pseudo-code:
for (int i=0;i < System.out().length(); i++) {
String grabbedtext += System.out().toString();
}out.println(grabbedtext);
Similar Messages
-
Re : how to print report output in DOT MATRIX printer
Hai
how to print report output in DOT MATRIX printer.
Thanks
maniCheck this
[http://help.sap.com/saphelp_nw04/helpdata/en/90/78f078030211d399b90000e83dd9fc/frameset.htm]
also check the SAP Note 129581 -
How to print the output of the screen in Dialog Programming
Hi,
Could anybody help how to print the output of a screen in the dialog programming. i can select 'Hard Copy' option in the 'Custumizing of Local Layout' Icon in the standard tool bar. but that prints the whole screen with the toolbar. i want to print only the output which is displayed on the screen. Please help..
Regards,
SwathiHi Swathi,
Ok. Do One thing. Go to menu bar and select Systems -> Own pool Request -> here you get the spool number. Select it and select the option "Print Directly" in tool bar.
Thanks. -
How to print an output stream on console.
Hi,
I am new to JAVA. I am trying to execute a command in runtime and I want to print the output on console and also redirect the output to a file.
Could anyone please help me?
This is what I wrote :
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec("cmd /c ipconfig");I am getting an output stream by : proc.getOutputStream(). I dont know how to print it on console and also how to redirect it to a file.
Could anyone please help me.
Thanks in advance.
BasavYou can do it this way :-
public static void main(String args[]) throws Exception {
ProcessBuilder builder = new ProcessBuilder("ipconfig", "/all");
Process process = builder.start();
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
FileWriter writer = new FileWriter(new File("C:/ipconfig.txt"));
String str;
while ((str = reader.readLine()) != null) {
System.out.println(str);
writer.write(str + System.getProperty("line.separator"));
writer.close();
reader.close();
}Let me know if it works for you. -
Tutorial on how to print multiple output pages
Hi,
I am rather sad that this forum does not provide a simple principle on how to printout multiple pages to newbie.
Below is a short contribution from me on how to print across multiple pages, other reader are also encourage to modify the code to provide more robust tutorial .
* How to use java to print across pages that are more than one
* Short contribution to java forum by Eric gan (Malaysia)
import java.awt.*;
import java.awt.geom.*;
import java.awt.print.*;
import java.awt.Graphics2D;
import java.awt.print.*;
import java.awt.print.Book;
import java.awt.print.Pageable;
import java.awt.Graphics2D;
import java.awt.Graphics;
public class Example implements Printable {
//--- Private instances declarations
private int row_cnt=30; // set the total number of row per page
private int cum_row_cnt=30; // set the counter to record total number of row per page to determine
// whether maximum pages should be increase depending on the programme requirement
private int max_pg=0; // set the maximum number of page
public Example () {
//--- Create a printerJob object
PrinterJob printJob = PrinterJob.getPrinterJob ();
printJob.setPrintable(Example.this);
if (printJob.printDialog()) {
try {
printJob.print();
} catch (Exception PrintException) {
PrintException.printStackTrace();
public void paint (Graphics g) {
Graphics2D g2d;
g2d = (Graphics2D) g;
int x=10;
int y=10;
for (int outline=0;outline<=160;outline+=20){
if (y>cum_row_cnt){
cum_row_cnt+=row_cnt;//counter should grow by value equal to row_cnt
max_pg++;
g2d.drawString("outline value ---> " +outline , x, y);
y+=10; // to set the row printing interval
} // end of paint procedure
public int print(Graphics g,
PageFormat pf, int pi)
throws PrinterException {
// normal routine to check when should java stop the print looping
if (pi >max_pg) {
return Printable.NO_SUCH_PAGE;
Graphics2D g2 = (Graphics2D) g;
int fontHeight=g2.getFontMetrics().getHeight();
int fontDesent=g2.getFontMetrics().getDescent();
double pageHeight = pf.getImageableHeight()-fontHeight;
double pageWidth = pf.getImageableWidth();
// setting for the translate and graphics clipping to enable printing on output pages
// row_cnt can be equal to pageHeight
// in this examples assumming pageHeight=20 rows
g2.translate(pf.getImageableX(), pf.getImageableY());
g2.translate(0f,-pi*row_cnt);
g2.setClip(0, (int)(row_cnt* pi),
(int) Math.ceil(pageWidth),
(int) Math.ceil(row_cnt));
paint(g2);
return Printable.PAGE_EXISTS;
public static void main (String [] args) {
Example example = new Example ();
System.exit (0);
ThankHello
I know that Pages is using its own algorithm to resize pages when it put several of them on a single sheet.
This is why I use this tip.
I draw a rectangle whose size is supposed to be the final one.
I give it a white background and a black border whose thickness is set to one point.
For the tests I just insert three page breaks so that the document is a four pages one.
I print it as is.
Doing that, I may measure the printed rectangle.
Of course, at first attempt it doesn't match the required size.
It's easy to compute the required adjustments.
When the correct factor is reached, it is easy to build the complete document so that it prints the correct size.
Doing that I never got odd results but maybe it's because I am a lucky guy.
Of course, disagreeing with one advice doesn't mean that I don't respect it.
I respect your opinion, _on other matters too_
Yvan KOENIG (from FRANCE mardi 6 mai 2008 17:24:09) -
How to send console output to a html page
hi,
i wrote a java program, in that i used "System.out.println()" to print the output in the console. Now i want to print this output as a html page. output file is a simple physical HTML file. Please help me regarding this issue. Thanks in advance.Hi,
you can use log4j.jar or comman-login.jar through you can do it. if you want more information related log4j then see this
http://www.roseindia.net/tutorials/log4j/index.shtml
Thanks, -
How to print this output. (Array)
Hi all. I have two String array:
String[] a = { "a", "b", "c", "d", "e" };
String[] b = { "b", "d" };
I want to print this two array into this output:
Output:
a
bb
c
dd
e
Anybody can help me how to get this output. I have try with a for loop, but it's not working.try this,
boolean found=false;
for(int i=0; i<a.length;i++)
found=false;
for(int j=0;j<b.length;j++)
if(a.equals(b[j])
found=true;
if(found==true)
System.out.println(a[i]+a[i]);
else
System.out.println(a[i]); -
How to see console output in Sun Java(TM) System Web Server 6.1 SP7?
Dear All,
I am having Sun Java(TM) System Web Server 6.1 SP7 installed on Windows 2000 Prof.
I have deployed few applications and they were running successfully.
From debugging point of view, i like to see the output from System.out.println .
Prior to SP7 there is a console which shows this output. But now the batch files only starts and stops the admin and site server services. Where to see for console output?
Is there command like tail.exe of Weblogic awailable for Sun Java System Web Server or any setting to be done in Admin?
Please revert.
-SameerResponse headers can be found in srvhdrs pblock.
Those can be manipulated by using set-variable
http://docs.sun.com/app/docs/doc/820-1638/6nda01tea?l=en&a=view#abuis
You can read more about these in
Sun Java System Web Server 6.1 SP8 Administrator's Configuration File Reference
http://docs.sun.com/app/docs/doc/820-1638?l=en
and
Sun Java System Web Server 6.1 SP8 NSAPI Programmer's Guide
http://docs.sun.com/app/docs/doc/820-1643?l=en -
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:
-SamHi 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 -
How to print the output string in inverted commas
hi all,
my question is
like i have a string
"welcome to java"
using println statement
i need to print the above statement in inverted commas
like the output should appear as
"welcome to java"This sounds like part of some homework but what the
heck ...
System.out.println("\\"welcome to java\\"");I was trying to anticipate bugs in this stupid forum sofftware, this should be
System.out.println("\"welcome to java\""); -
How to see console outputs at the Netweaver Developr Studio
Hello,
I am using the Netweaver Developr Studio
Let's say my program is having this line: System.out.println("Hello");
Is there any way to see this output at the Developr Studio console?Hi Roy,
since your WebDynPro application runs on the server & not within local JVM, you can only see this on the machine which crashes when you try to execute
System.out.println(".");
System.exit(0);
. would be then seen on the host which crashed, under
/sap/usr/cluster/server/managers/console_logs/
hope this helps (:,
ds
ps. tail is a really cool unix tool (tail -f <logFile>.log for follow) to make such contemplation even better -
OEM 10G -- how to print the output of a table in a html report
Hi everyone,
I am trying to print the out of a particular table from the DB using OEM but having some hard time to do so, does any one know the way. Thanks for reading.
Oracle version: 10.2
OS: Windows xp
Regards,
katheriafter login to the OEM ,
you want the rows of the table or structure of the table?
you can find administration tab top of the page,
again you database objects -> tables
new web page will open -> there you have to enter schema name and table name -> you will get the list of table and then click to view , data types and sizes and all.. -
How to see "console output" from the java web start ?
Hi all.
I wish to see logging infomation from the client side when using java web start technologie (java1.6 version).
Please help.
Thak'sUse the "Advanced" tab of the Java Control Panel to turn on "tracing" and/or the Java Console.
see:
http://java.sun.com/j2se/1.5.0/docs/guide/javaws/developersguide/troubleshooting.03.06.html
/Andy -
How to print output of XML Publisher report in different trays of a printer
Hi All,
I have a requirement in XML Publisher Report. I need to print all pages other than last one in one tray of a printer and the last page has to be printed in another tray of the same printer.
Can anyone help me out...
Thank You..I do not think it is possible to send all the pages to one tray and send only the last page to a different tray. However, you may review the following notes:
Note: 357402.1 - How to Print the Output to a Different Paper Size Using XML Publisher Delivery Manager?
https://metalink2.oracle.com/metalink/plsql/ml2_documents.showDocument?p_database_id=NOT&p_id=357402.1
Note: 394130.1 - How To Enable Printer Options Such As Duplex Printing Or Tray Selections For Bitmap Concurrent Programs
https://metalink2.oracle.com/metalink/plsql/ml2_documents.showDocument?p_database_id=NOT&p_id=394130.1 -
How to print a HTML file in browser look using DocPrintJob
Hello guys,
Does anyone know how to print HTML output/file into browser look?
I'm using DocPrintJob and the DocFlavor set to DocFlavor.INPUT_STREAM.AUTOSENSE.
posted below is my code :
public class BasicPrint {
public static void main(String[] args) {
try {
// Open the image file
String testData = "C:/new_page_1.html";
InputStream is = new BufferedInputStream(new FileInputStream(testData));
DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
// Find the default service
PrintService service = PrintServiceLookup.lookupDefaultPrintService();
System.out.println(service);
// Create the print job
DocPrintJob job = service.createPrintJob();
Doc doc= new SimpleDoc(is, flavor, null);
// Monitor print job events; for the implementation of PrintJobWatcher,
// see e702 Determining When a Print Job Has Finished
PrintJobWatcher pjDone = new PrintJobWatcher(job);
// Print it
job.print(doc, null);
// Wait for the print job to be done
pjDone.waitForDone();
// It is now safe to close the input stream
is.close();
} catch (PrintException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
static class PrintJobWatcher {
// true iff it is safe to close the print job's input stream
boolean done = false;
PrintJobWatcher(DocPrintJob job) {
// Add a listener to the print job
job.addPrintJobListener(new PrintJobAdapter() {
public void printJobCanceled(PrintJobEvent pje) {
allDone();
public void printJobCompleted(PrintJobEvent pje) {
allDone();
public void printJobFailed(PrintJobEvent pje) {
allDone();
public void printJobNoMoreEvents(PrintJobEvent pje) {
allDone();
void allDone() {
synchronized (PrintJobWatcher.this) {
done = true;
PrintJobWatcher.this.notify();
public synchronized void waitForDone() {
try {
while (!done) {
wait();
} catch (InterruptedException e) {
}the printed ouput for this code will be look like this
<html>
<body>
<div style="page-break-after:'always';
background-color:#EEEEEE;
width:400;
height:70">
testPrint</div>
ABCDEFGHIJK<p>
</p>
</body>
</html>however, the output that i want is the HTML in browser look not HTML code itself.
i've tried to change the DocFlavor into any TEXT_HTML type but it gives error:
sun.print.PrintJobFlavorException: invalid flavor if you guys has any idea or solution, can you share with me... already search in Google but still not found any solution
Thanks in advanced.hi,
do the following
URL url = null;
try
url = new URL("http://www.xyz.com");
catch (MalformedURLException e)
System.out.println("URL not correct " + e.toString());
if (url != null)
getAppletContext().showDocument(url,"_blank"); //shows the page in a new unnamed top level browser instance.
}hope that helpz
cheerz
ynkrish
Maybe you are looking for
-
I'm using InDesign CS3 on a couple of different Macs on Leopard and Snow Leopard. When I save a document I usually copy (command-C) the name in the "Save as" field, create a new folder, and then paste (command-V) the name into the "Name of new folder
-
Hello, I have the 2008 (2.4ghz) black macbook. I am trying to connect to my old iMac g4 to transfer some files. I am having difficulties such that the Macbook won't recognize the iMac when they are connected via firewire and the iMac is in FW disc mo
-
Photo stream in referenced mode?
I'd like to have my photo stream show up in referenced mode in Aperture. Anyone know how to do this?
-
ME55 DUMP error after EHP upgrade
Hi all, We recently upgraded to SAP ECC EHP7 version (Basis 740) and we are getting some kind of dump error upon entering ME55. Is this a common issue? I could not find the same issue noted before. How can I resolve it? I attached the error screen th
-
Can i set a default transition for final cut pro x
Can I set a default transition for Final Cut Pro X? I'm doing a multicamera edit and would like all edit points to have a cross dissolve transisiton. Can I make this happen by default? Thanks!