Printing from a servlet...

Hi, Does anyone know how to assign a printer to a PrinterJob without the dialog box ? Thanks for answering !

Thanks, I know, but in fact I have to print on 2 different printers, and so I can't do it like this, don't you know if an attribute exists to choose the printer, by its system name or by its IP address ?

Similar Messages

  • Automatic pdf print from a servlet?

    Hi..I have a one servlet that displays a pdf file in the browser (IE). Under normal circumstance, the user would print the pdf from the Acrobat Reader toolbar displayed within the browser. Well now, the user wants to have the pdf file printed automatically, because it is "too confusing" to choose between the browser print button and Reader's! My idea is to have the servlet contain a method for handling pdf print. Any ideas on an existing API or if this can even be done? Thanks!!

    I ran into a similar situation recently and found one cheap (smells a bit like a hack) option to give the illusion of direct printing. If you embed Acrobat Reader as an object in your page then you can give it a width and height of 0, effectively hiding it. Then use the print() function to make it print from your own button in the page. Something like this:
    <OBJECT CLASSID="clsid:CA8A9780-280D-11CF-A24D-444553540000" WIDTH=0 HEIGHT=0 ID=MYPDF>
    <PARAM NAME="SRC" VALUE="/servlet/MyServlet">
    </OBJECT>
    Then a button on the same page can make the pdf print.
    <BUTTON name='printButton' onClick='MYPDF.print()'>Print</BUTTON>
    Your confused users still have to choose that button however -- I don't think you can override the behaviour of the browser's print button.
    I've heard of some plug-in called ActivePDF that might also help you but I don't know much about it (do a search).

  • Initiating report printing from a web page to a network printer

    I want to print to a user's network printer from a servlet. My development environment is a single machine so everything works just fine. The production environment is 3-tiered -- database server, web server and client. In the 3-tiered configuration the PrintReport class executes on the web server and seems to get lost. How can I print in the 3-tiered environment and still give the user the chance to change the printer or the print attributes? My java code currently displays a print dialog box to the user in the 1-tier environment.

    I don't think you're going to be able to do that from a web page. Imagine if you visited my site and I decided that your printer should print every image in my "Special Donkey Pictures" directory...
    You might be able to create an applet that you can feed the webpage into - into a JTextPane for instance, implement Printable and print from that. I say that without any real knowledge of Applets or what sort of security/signing issues there might be with that.

  • Sending an email from a servlet

    Hi Guys,
    Im trying to send an email from a servlet. I am using the following code:
    IMPORTING LIBRARIES
    import java.util.*;
    import java.io.*;
    import javax.servlet.http.*;
    import javax.servlet.*;
    //importing JDBC
    import java.sql.*;
    //email
    import java.net.*;
    import java.text.*; // Used for date formatting.
    BEGIN CLASS
    public class Email3 extends HttpServlet
         private Socket smtpSocket = null;
         private DataOutputStream os = null;
         private DataInputStream is = null;
    public void doPost (HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException
    PrintWriter out = res.getWriter();
    OUTPUT TAGS FOR WEBPAGE
         out.println("<html>");
    out.println("<head>");
    out.println("<title>FYP</title>");
    out.println("</head>");
    out.println("<body>");
    out.println("<center>");
    send email
              //Date dDate = new Date();
              //DateFormat dFormat = _
         //DateFormat.getDateInstance(DateFormat.FULL,Locale.US);
         String m_sHostName="localhost";
         int m_iPort=25;
              try
              { // Open port to server
                   smtpSocket = new Socket(m_sHostName, m_iPort);
                   os = new DataOutputStream(smtpSocket.getOutputStream());
                   is = new DataInputStream(smtpSocket.getInputStream());
                   if(smtpSocket != null && os != null && is != null)
                   { // Connection was made.  Socket is ready for use.
                        out.println("Connection was made. Socket is ready for use.");
                        //[ Code to send email will be placed in here. ]
                        try
                             {   os.writeBytes("HELLO\r\n");
                             // You will add the email address that the server
                             // you are using know you as.
                             os.writeBytes("MAIL From: <[email protected]>\r\n");
                             // Who the email is going to.
                             os.writeBytes("RCPT To: <[email protected]>\r\n");
                             //IF you want to send a CC then you will have to add this
                             os.writeBytes("RCPT Cc: <[email protected]>\r\n");
                             // Now we are ready to add the message and the
                             // header of the email to be sent out.
                             os.writeBytes("DATA\r\n");
                             os.writeBytes("X-Mailer: Via Java\r\n");
                             //os.writeBytes("DATE: " + dFormat.format(dDate) + "\r\n");
                             os.writeBytes("From: Me <[email protected]>\r\n");
                             os.writeBytes("To: YOU <[email protected]>\r\n");
                             //Again if you want to send a CC then add this.
                             os.writeBytes("Cc: CCDUDE <[email protected]>\r\n");
                             //Here you can now add a BCC to the message as well
                             //os.writeBytes("RCPT Bcc: BCCDude<[email protected]>\r\n");
                             String sMessage = "Your subjectline.";
                             os.writeBytes("Subject: Your subjectline here\r\n");
                             os.writeBytes(sMessage + "\r\n");
                             os.writeBytes("\r\n.\r\n");
                             os.writeBytes("QUIT\r\n");
                             // Now send the email off and check the server reply.
                             // Was an OK is reached you are complete.
                             String responseline;
                             while((responseline = is.readLine())!=null)
                             {  // System.out.println(responseline);
                             out.println("responseline= "+responseline+"<br>");
                             if(responseline.indexOf("Ok") != -1)
                                  //out.println("responseline"+responseline);
                             break;
                             catch(Exception e)
                             {  System.out.println("Cannot send email as an error occurred.");
                                  out.println("Cannot send email as an error occurred.");
              catch(Exception e)
              { System.out.println("Host " + m_sHostName + "unknown"); }
              out.println("</center>");
              out.println("</body>");
              out.println("</html>");
              out.close();
    }//end class
    it compiles fine, the connection was made ok but im not receiving the email. When the email is sent off the server reply does not seem to be Ok, as the print statement i tried there is not being executed. When i print the content of my responseline= variable before the if statement i get the following:
    Connection was made. Socket is ready for use. responseline= 220 centaur.elec.qmul.ac.uk ESMTP Exim 3.16 #2 Thu, 09 Jan 2003 15:54:34 +0000
    responseline= 500 Command unrecognized
    responseline= 250 is syntactically correct
    responseline= 550 relaying to prohibited by administrator
    responseline= 500 Command unrecognized
    responseline= 503 No recipient(s).
    responseline= 500 Command unrecognized
    responseline= 500 Command unrecognized
    responseline= 500 Command unrecognized
    responseline= 500 Command unrecognized
    responseline= 500 Command unrecognized
    responseline= 500 Command unrecognized
    responseline= 500 Command unrecognized
    responseline= 500 Command unrecognized
    responseline= 221 Closing connection. Good bye.
    Can anyone help?
    Is there an easier way to send an email from a servlet?
    Thanks
    tzaf

    It's not a matter of "easier way" to send mail from servlet...you are missing a crucial element in your code: authorization to send mail. You need something like this (some of which you have already so note what is different):
            Properties properties = new Properties();
            properties.put("mail.smtp.host", String3 );
            properties.put("mail.smtp.dsn.notify", "SUCCESS" );
            properties.put("mail.smtp.host", "mailservernamegoeshere");
            properties.put("mail.smtp.auth", "true");
            MyAuthenticator auth = new MyAuthenticator();
            auth.setUser("user whos account you want to use goes here");
            auth.setPassword("user password goes here");
            Session session = Session.getDefaultInstance( properties,auth );Here is the auth class:
    class MyAuthenticator extends Authenticator {
       protected String m_strUser     = null;
       protected String m_strPassword = null;
       protected PasswordAuthentication getPasswordAuthentication()  {
          return new PasswordAuthentication(m_strUser,m_strPassword);
       public void setUser(String strUser)  {
          m_strUser = strUser;
       public void setPassword(String strPassword)  {
          m_strPassword = strPassword;

  • Including JSPFs from Java Servlets[Solved]

    EDIT:
    After reading up a bit more on JSP Fragments I realized that they don't work from a Servlet environment. I should have researched a bit more before posting. By switching the files to JSPs, everything works perfectly.
    Original:
    Hopefully I can make this post make sense because there is very little code I can post in a public environment like this. Here goes nothing...
    I have a Servlet, that includes a JSP file using RequestDispatcher.include(). This JSP works fine, and it gets compiled and shown properly. In this "wrapper" jsp, there are multiple calls to various methods in a class which do things such as printing, and including more jspfs, based on the data stored in an XML file.
    For some reason, when including JSPFs from the java methods, the raw JSPF's content is being displayed, rather than a compiled version of the content.
    Here is an example JSPF:
    <%= "Content Coming from a JSPF" %>Here is the code that includes the JSPF:
    this.request.getRequestDispatcher(path).include(this.request, this.response);The JSPF shows up in the right spot and everything, but it's the raw JSPF content, not what it should be showing.
    Am I doing something wrong?
    Thanks,
    -Nivek98
    Message was edited by:
    nivek98

    Hi,
    I dont think you can directly do this
    tagLT %@ include file="/irj/go/km/docs/etc/public/mimes/PMIS/Static%20Contents/sample.html"% tagGT
    check what happens if you directly paste this URL in browser.
    Instead, you can create a KM Document iView from the HTML and paste the URL of the iView in the JSP. Or the best way is to create a page, assign the iViwe to the page and generate a short URL for the page and have this short URL in your include.
    You can check this for short URLs
    http://help.sap.com/saphelp_nw70/helpdata/EN/b3/7b8163404448e7aad7899c0b30313e/content.htm
    Srini
    Edited by: Sinivasan Rajamani on Feb 18, 2010 5:38 AM
    Edited by: Sinivasan Rajamani on Feb 18, 2010 5:36 PM

  • EJB in Glassfish V2 from a Servlet in SJSWS

    HI, I'm trying to use a EJB deployed in Glassfish from a servlet in the web server. I followed the steps in EJB_Faq of Glassfish site and they work
    perfectly in Tomcat, but when I try it on Sun Web Server 7.0u1 it fails. On the web server log there is an exception when trying to create InitialContext, but I think
    it is because of a warning that the server shows before the error. It doesn't load the javaee.jar file because is "Offending a class", the Servlet class.
    Anyone has tried this, call an EJB in Glassfish from Sun Web Server? It works in Tomcat but the Web Server doesn't load the javaee.jar file and I think this is the reason that the call fails.

    This is the code for the EJB:
    package jpm.business;
    import java.util.List;
    import javax.ejb.Stateless;
    @Stateless(mappedName="ejb/soloEJB")
    public class JavaPlatformManagerBean implements jpm.business.JavaPlatformManagerRemote, jpm.business.JavaPlatformManagerLocal {
    public String getNombre(){
    return "Minchez";
    public String toString(){
    return "Minchez ";
    And this is the part of the servlet that looks for the EJB:
    try{
    java.util.Properties props = new java.util.Properties();
    props.setProperty("java.naming.factory.initial",
    "com.sun.enterprise.naming.SerialInitContextFactory");
    props.setProperty("java.naming.factory.url.pkgs",
    "com.sun.enterprise.naming");
    props.setProperty("java.naming.factory.state",
    "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
    props.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
    props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
    out.print("1");
    InitialContext ic = new InitialContext(props);
    out.print("2");
    JavaPlatformManagerRemote jpmr = (JavaPlatformManagerRemote)ic.lookup("ejb/soloEJB");
    out.print("-" + jpmr.getNombre());
    out.print("3");
    } catch(Exception e){ out.println(e.toString()); }
    (I just deleted some comments, but if there is an error, just complete the declarations)
    The EJB's .jar is deployed on Glassfish and the Servlet's .war is deployed on SJSWS or Tomcat. As the FAQs says on Glassfish forum, you have to add some jars to the web server classpath. Copy this jars to a folder named shared/lib on tomcat installation: javaee.jar, appserv-rt.jar, appserv-ext.jar, appserv-deployment-client.jar and jmxremote_optional.jar the last one I don't know if its necessary but I copied also, they are on Glassfish lib directory.
    If you try in tomcat it works fine, the servlet receives the String form the EJB method. But when you try it in SJSWS the javaee.jar file its not loaded, fails on "validateJar(....)" and I think this is the reason the servlet doesn't find de EJB.
    I'm using:
    Glassfish V2
    SJS Web Server 7.0u1
    Tomcat 5.5.17

  • PDF Print from joomla

    Hello everybody
    I am newbie and dont know much about PHP coding.
    Now i have a design for a Calender and I am using joomla for my website. In joomla i have a component names Eventlist.
    So what i want to do is, to print all the events of everyday as PDF on my Design.
    Can anyone help me or explain me what to do.
    Is it possible to install Acrobat on my website?
    I will be thankful to everybody here.
    Regards

    I ran into a similar situation recently and found one cheap (smells a bit like a hack) option to give the illusion of direct printing. If you embed Acrobat Reader as an object in your page then you can give it a width and height of 0, effectively hiding it. Then use the print() function to make it print from your own button in the page. Something like this:
    <OBJECT CLASSID="clsid:CA8A9780-280D-11CF-A24D-444553540000" WIDTH=0 HEIGHT=0 ID=MYPDF>
    <PARAM NAME="SRC" VALUE="/servlet/MyServlet">
    </OBJECT>
    Then a button on the same page can make the pdf print.
    <BUTTON name='printButton' onClick='MYPDF.print()'>Print</BUTTON>
    Your confused users still have to choose that button however -- I don't think you can override the behaviour of the browser's print button.
    I've heard of some plug-in called ActivePDF that might also help you but I don't know much about it (do a search).

  • 'Dunning Letter Print from Dunning Letter Generate'

    hi,
    How can i run the "Dunning Letter Print from Dunning Letter Generate" standard program without runing the spwaned program called 'Dunning Letter Generate'.I mean i want to run the 'Dunning Letter Print from Dunning Letter Generate'(execution method: report) independently.
    I need to pass the parameters to the 'Dunning Letter Print from Dunning Letter Generate' directly instead of passing to the spwaned program ''Dunning Letter Generate".
    Thanks
    Devender

    Hi Gareth,
    New parameters to be add are:
    Tier : <xxxx>
    Service Segment: <xxxxx>
    Account Manager: <xxxx>
    Location where I am picking these 3:
    navigation:select any AR responsibility
    customer->standard(query with any customer)->customer address
    we have enabled 'site use information' dff in customer address window, from this dff we are taking these 3 parameters.
    reason to add these 3 parameters:
    we cant treat all the customers same. so we need to send some smooth(no harsh) dunning letters to some of our most trusted customers. so how can we identify gud customers in the list.
    so we have enabled site use information dff. those customers who is have values for these 3 parameters. will be treated as v good and reguler customers for us. so for them we can send other dunning letters.
    note*: this is to identify the customers like reguler customers,non requler customers.
    bez in spwaned program we have parameters like 1.customer low 2.customer high. thats it .so it is very difficult to find out the nature of customer.
    pls advice me on this..to proceed further..
    Thanks
    Devender

  • I can't print web pages since a recent upgrade to 4.01. The print command works but the page comes out empty. right now a copy the link to IE and print from there. HELP!

    When printing from the mozilla 4.01 browser the printer spits out blank pages. It seems like it happened after downloading and running mozilla 4.01 browser.
    I have to copy the link to IE (boo!) to print the coupon or page on my printer.
    Why?

    The "Use custom settings for history" selection allows to see the current history and cookie settings, but selecting this doesn't make any changes to history and cookie settings.
    Firefox shows "Use custom settings for history" as an indication that at least one of the history and cookie settings is not the default to make you aware that changes were made.
    If all History settings are default then the custom settings are hidden and you see "Firefox will: (Never) Remember History".
    "Never Remember History" means that Private Browsing is active and "Always use private browsing mode" gets a checkmark.
    You need to remove the checkmark on "Always use private browsing mode" to leave Private Browsing mode or chose the "Remember History" setting.
    *https://support.mozilla.org/kb/Private+Browsing

  • Print from ipad if i connect a usb connector to my ipad can i connect my printer to it and print??as im thinking of buying the new ipad for work but i must be able toprint

    hi can any one help i want to get the new ipad for work but i need to print.i see i can buy a usb connector can i print if i plug my printer into the usb.

    If you have a USB printer connected to your computer, Mac or PC, you can activate or install AirPrint and print from your iPad over wifi without any special apps.
    Activate AirPrint in Mac OS X;
    http://netputing.com/airprintactivator/
    Add AirPrint to Windows;
    http://jaxov.com/2010/11/how-to-enable-airprint-service-on-windows/

  • How can I print from the icon in FF5?

    I have been unable to print from any of the icons in FF5. This has only occurred in the past few days. The only way I can print is to "Select" on the page, and then "Print Selection" on the print screen. I can print from IE by using the icons.
    This is also true with my Yahoo email.

    In Mac OS X, right-clicking the document's icon brings up a similar menu, but documents are printed from the application, not from the OS. The application is launched, the document opened,and the document sent to the printer, bypassing only the Print dialogue.
    The same route may be triggered by dragging and dropping the file's icon onto the printer's icon in the Dock.
    Regards,
    Barry

  • How to call a specific method in a servlet from another servlet

    Hi peeps, this post is kinda linked to my other thread but more direct !!
    I need to call a method from another servlet and retrieve info/objects from that method and manipulate them in the originating servlet .... how can I do it ?
    Assume the originating servlet is called Control and the servlet/method I want to access is DAO/login.
    I can create an object of the DAO class, say newDAO, and access the login method by newDAO.login(username, password). Then how do I get the returned info from the DAO ??
    Can I use the RequestDispatcher to INCLUDE the call to the DAO class method "login" ???
    Cheers
    Kevin

    Thanks for the reply.
    So if I have a method in my DAO class called login() and I want to call it from my control servlet, what would the syntax be ?
    getrequestdispatcher.include(newDAO.login())
    where newDAO is an instance of the class DAO, would that be correct ?? I'd simply pass the request object as a parameter in the login method and to retrieve the results of login() the requestdispatcher.include method will return whatever I set as an attribute to the request object, do I have that right ?!!!!
    Kevin

  • Error while opening a Office 2007 Excel (.xlsx) from a Servlet

    Hi All,
    Actually i am trying to open an excel file from a servlet. It works fine when the file format is .xls. But if it is .xlsx it gives the below error.
    "The file you are trying to open .xlsx is in a different format than specified by the file extension. verify the file is not corrupted and is from trusted source before opening the file. Do you want to open the file now?"
    There is a link in the application. When we click the link it calls the servlet. The servlet calls the DAO. The DAO queries the DB and the whole output is stuffed into a StringBuffer and the StringBuffer is written to the ServletOutputStream. I have used
    File newFile = new File("ABC.xslx");
    response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
    I have also included the below in the web.xml file.
    <mime-mapping>
    <extension>xlsx</extension>
    <mime-type>application/vnd.openxmlformats-officedocument.spreadsheetml.sheet</mime-type></mime-mapping>
    Kindly help me out.
    Thanks.

    Hi,
    I tried to create an excel through POI 3.5 using a simple java program. I am getting the same error when i try to open it.Below is my code. Kindly let me know the problem.
    I am getting the error ""The file you are trying to open .xlsx is in a different format than specified by the file extension. verify the file is not corrupted and is from trusted source before opening the file. Do you want to open the file now?" when opening the .xlsx file.
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.File;
    import java.io.IOException;
    import java.util.ArrayList;
    import org.apache.poi.hssf.usermodel.HSSFRow;
    import org.apache.poi.hssf.usermodel.HSSFSheet;
    import org.apache.poi.hssf.usermodel.HSSFWorkbook;
    public class test {
    public static void main(String args[]) throws IOException{
    //ExportLobBean exportLobsForm = null;
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sheet = wb.createSheet();
    //ArrayList lobList = ExportLobBO.getArrayList();
    //int length = lobList.size();
    int rowCount=0;
    int count=0;
    HSSFRow headerRow = sheet.createRow((short) 0);
    HSSFRow dataRow = null;
    //Creating Column Names
    headerRow.createCell((short)0).setCellValue("LOB-ID");
    headerRow.createCell((short)1).setCellValue("LOB-NAME");
    headerRow.createCell((short)2).setCellValue("WEIGHT");
    for(int i=0;i<5;i++){
    rowCount++;
    sheet.createRow((short)rowCount);
    //exportLobsForm = (ExportLobBean)lobList.get(count);
    headerRow.createCell((short)0).setCellValue(1);
    //LOGGER.info("Lob id "+exportLobsForm.getStrLobId());
    headerRow.createCell((short)1).setCellValue(2);
    //LOGGER.info("Lob name"+exportLobsForm.getStrLobName());
    headerRow.createCell((short)2).setCellValue(3);
    //LOGGER.info("Lob weight"+exportLobsForm.getStrLobWeight());
    count++;
    File f = new File("c:\\test.xlsx");
    FileOutputStream fos = new FileOutputStream(f);
    wb.write(fos);
    }

  • I can no longer print from a website. I can from other browsers but not Mozilla. Help

    I used to be able to print any time I needed to. Then the print became so small I could not read it. Then the pages I printed from the website, printed blank pages. I contacted Thunderbird because this was first noted on email when I tried to print something from a website, they told me it was a Mozilla problem. So I then tried to print straight from the website and got the same thing. Nothing. The page is completely blank when printed.

    These suggestions are not the problem and I have contacted HP and they have run all the diagnostics and they say the problem is not with the printer or the software. All other browsers print, just not Mozilla

  • MFP M127fn connected, test printing OK, can't print from applications

    Hello Everyone!
    I have just set up my M127fn via USB on a Windows 8 system. The set up went fine. I have a small stack of test pages from the HP software, but it won't print anything from any applications like MSOffice. The HP diagnostic software (Print and Scan Doctor 4.6)  can communicate with the printer and everything checks out OK.
    Any suggestions?
    Thanks in advance.

    Hello! 
    I have replied twice to your last posting, but have heard no response. Unless a solution can be presented quickly, I fell I must return the product. LPug and play was introduced with Windows 95 and this HP product has not lived up to that 20 year old technological standard. My previous replies are copied below.
    Please respond soon.__________________________________________
    Re: MFP M127fn connected, test printing OK, can't print from applications
    Options 
    ‎01-31-2015 08:06 AM
    Hello again!
    I haven't heard a response to my most recent reply. Is there anything you can suggest before I give up and return this HP product to the store? I would like a quick resolution to this. As an update to my previous email (copied below), printing is no longer working through Adobe Reader.
    Thanks,
    Chris
    Re: MFP M127fn connected, test printing OK, can't print from applications
    Options 
    ‎01-28-2015 01:08 PM
    Hi,
    Thanks for getting back to me. I have tried a variety of different programs:
    Mozilla Thinderbird (email) - no results
    MS Word - no
    ms excel - no
    Finale (music software) - no
    Adobe Reader - yes!
    Google Chrome - yes!
    NotePad - yes!
    perplexing!

Maybe you are looking for

  • Quick Trim option in Save for Web & Devices

    Hi, a feature to do a quick Trim in Save for Web & Devices dialogue would be great, especially if it was enabled with a checkbox, then when you enable it, it activates a dialogue with the three options that already exist in Trim option (Transparent p

  • What's the difference between last seen and last a...

    What's the difference between  last seen and last activity by a contact's name?  Please be very specific  Many thanks.

  • A diff instance design

    Hey, I want to write a diff instance class. The DiffInstance will get two instances of the same class and will return a collection of difference between the instance. This is done because there are a lot of services that triger by changes in the mode

  • Lockbox user exit

    Dear Experts, For lockbox procedure in SAP customer identification is the primary task of the initial data processing of each lockbox payment. Finding the corresponding document clearing information is the second task. Lockbox program RFEBLB00 for BA

  • "Why Apple do not fix light sensor bug in ios 6 ipod touch 4g plz give me update for this"

    Light Sensor increase but not Decreas light