Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
monicka rk akilan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9279
10
Linux Mac OS X Windows
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic