• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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......
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Using Headless Mode In Java SE
 
Live a little! The night is young! And we have umbrellas in our drinks! This umbrella has a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic