File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Print not working in live but working in localhost- (java.awt.HeadlessException) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Print not working in live but working in localhost- (java.awt.HeadlessException)" Watch "Print not working in live but working in localhost- (java.awt.HeadlessException)" New topic
Author

Print not working in live but working in localhost- (java.awt.HeadlessException)

monicka rk akilan
Greenhorn

Joined: Jan 04, 2013
Posts: 8
Hello every one,

Am using struts1.3. Am struking in printing when i tried in local host its working perfectly.
But when i move to live its shows exception.
--------------------------------------------------------------------------------------------------------------------------------------
ype Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: java.awt.HeadlessException
org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:520)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:427)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:228)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

root cause

java.awt.HeadlessException
sun.print.PSPrinterJob.printDialog(PSPrinterJob.java:422)
report.Printing.Print.printToPrinter(Print.java:97)
report.Printing.Print.main(Print.java:45)
com.lr.LRMasterAction.Print(LRMasterAction.java:66)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:601)
org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:269)
org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:170)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:425)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:228)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

----------------------------------------------------------------------------------------------------------------------------------
here is my coding......

package report.Printing;

import com.dao.dto.LrMasterDTO;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

public class LRText implements Printable{
int fontSize=8;
LrMasterDTO lm;

FileWriter outFile ;
public void setLr(LrMasterDTO lm)
{
this.lm=lm;
} public int print(Graphics g, PageFormat pf, int pageIndex)
throws PrinterException {

g.setFont(new Font("TimesRoman",Font.PLAIN,fontSize));
Graphics2D g2d = (Graphics2D)g;
g2d.translate(pf.getImageableX(), pf.getImageableY());

g.setColor(Color.BLACK);
g.drawString(lm.getLrDate(),140,65);
g.drawString(lm.getLrNumber(),200,65);


/* tell the caller that this page is part of the printed document */
return Printable.PAGE_EXISTS;
}


public String printing()
{
String result = null;
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(this);
boolean ok = job.printDialog();

if (ok) {
try {
job.print();
result="printed successfully";
} catch (PrinterException ex) {
result=ex.getMessage();

}
}
return result;
}

}
-------------------------------------------------------------------------------------------------------------------------------


please can any one help me.......

Thanks in advance......
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8997
    
    9

Using Headless Mode In Java SE


[How To Ask Questions On JavaRanch]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Print not working in live but working in localhost- (java.awt.HeadlessException)