Generaating new doc file with jsp servlet.

Hi friends,
I developed an application with JSP
In that i need a data to be fetched nd write in .doc file.
I mean I want to create new word file nd get my data in that
like reports generation.
How can i make this.
help me pls

.doc file: I don't think there is any reporting tool that creates .doc. You can create .rtf files with Oracle Reports and many other tools.

Similar Messages

  • How to open a ".doc" file with ms word directly with this servlet?

    Here is a servlet for opening a word or a excel or a powerpoint or a pdf file,but I don't want the "file download" dialog appear,eg:when i using this servlet to open a word file,i want open the ".doc" file with ms word directly,not in IE or save.
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.util.*;
    public class OpenWord extends HttpServlet {
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    doPost(request,response);
    public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException {
    String strFileName = req.getParameter("filename");
    int len = 0;
    String strFileType1 = "application/msword";
    String strFileType2 = "application/vnd.ms-excel";
    String strFileType3 = "application/vnd.ms-powerpoint";
    String strFileType4 = "application/pdf";
    String strFileType = "";
    if(strFileName != null) {
         len = strFileName.length();
         if(strFileName.substring(len-3,len).equalsIgnoreCase("doc")) {
              strFileType = strFileType1;
         } else if(strFileName.substring(len-3,len).equalsIgnoreCase("xls")) {
              strFileType = strFileType2;
         } else if(strFileName.substring(len-3,len).equalsIgnoreCase("ppt")) {
              strFileType = strFileType3;
         } else if(strFileName.substring(len-3,len).equalsIgnoreCase("pdf")) {
              strFileType = strFileType4;
         } else {
              strFileType = strFileType1;
    if(strFileName != null) {
         ServletOutputStream out = res.getOutputStream();
         res.setContentType(strFileType); // MIME type for word doc
    //if uncomment below sentence,the "file download" dialog will appear twice.
         //res.setHeader("Content-disposition","attachment;filename="+strFileName);
         BufferedInputStream bis = null;
         BufferedOutputStream bos = null;
         String path = "d:\\"; //put a word or a excel file here,eg a.doc
         try {
         File f = new File(path.concat(strFileName));
         FileInputStream fis = new FileInputStream(f);
         bis = new BufferedInputStream(fis);
         bos = new BufferedOutputStream(out);
         byte[] buff = new byte[2048];
         int bytesRead;
         while(-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
         bos.write(buff, 0, bytesRead);
         } catch(NullPointerException e) {
         System.out.println ( "NullPointerException." );
         throw e;
         } catch(FileNotFoundException e) {
         System.out.println ( "FileNotFoundException." );
         throw e;
         } catch(final IOException e) {
         System.out.println ( "IOException." );
         throw e;
         } finally {
         if (bis != null)
         bis.close();
         if (bos != null)
         bos.close();

    Hello!
    Does some one of you had open a MS word file (.doc) in Java search for a token like [aToken] replace it with another text and then feed it to a stream of save it?
    I want to build a servlet to open a well formatted and rich on media (images) ms word document search for tokens and replace them with information form a web form.
    Any Ideas?
    Thank you in advanced.

  • Downloading PDF file with a servlet

    I'm working on a web application that dynamicaly creates a PDF file and then writes each character to the ServletOutputStream. Ideally, the browser is supposed to recognize the "application/pdf" MIME type and force the file to be downloaded (or opened from current location if the user should choose). When I test it on my local system, the file downloads but it uses the servlet as the file name. On my webserver I get the following problems.
    1) On all the browsers I've tested (except Internet Explorer), the output is being printed in ASCII to the display which keeps the file from downloading. Internet Explorer is the only browser that will actually download the file.
    2) When it does attempt to download the file, it is creating a file with the servlet as the name as opposed to the filename that I am assigning during creation.
    I've been reading all the related posts that I could find in these Forums but haven't been able to find a solution. If anybody has any ideas, I would greatly appreciate your knowledge. Please note that I have set up MIME-mapping for the PDF extension in the WEB.XML file on my web server.
    Here is some servlet code that handles the PDF creation and download:
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    InputStream in = null;
    ServletOutputStream out = null;
    String dir = "/www/mydirectory/";
    try {
    // Create the PDF file and retrieve the filename
    String filename = PDFCreator.main();
    //Flush the response stream and then reset it for writing a PDF to the display
    response.reset();
    response.setContentType("application/pdf");
    response.setHeader("Content-Disposition", "attachment; filename="+filename);
    out = response.getOutputStream();
    in = new BufferedInputStream( new FileInputStream(dir+filename));
    int ch;
    while ( (ch = in.read()) != -1 ) {
    out.print( (char)ch );
    } catch (Exception e) {
    e.printStackTrace();
    } finally {
    if( in != null ) {
    in.close();
    if( out != null ) {
    out.flush();
    out.close();

    Your code looks correct.
    Apparently other people too have been having problems with pdf's. These links may help you solve the problem.
    http://forum.java.sun.com/thread.jsp?forum=54&thread=100793
    http://forum.java.sun.com/thread.jsp?forum=33&thread=250668
    http://forum.java.sun.com/thread.jsp?forum=33&thread=63282
    Redirecting may not be a good idea due to url hacking. Streaming the output would be the best way to go.

  • How to open a doc file using jsp Anchor tag

    when i am trying to open a doc file using a jsp it is opening with out proper alignment.
              how to open a doc file with proper alignment using Anchor Tag in JSp Page
              

    Hello!
    Does some one of you had open a MS word file (.doc) in Java search for a token like [aToken] replace it with another text and then feed it to a stream of save it?
    I want to build a servlet to open a well formatted and rich on media (images) ms word document search for tokens and replace them with information form a web form.
    Any Ideas?
    Thank you in advanced.

  • How to display the PPT, PDF, XL, DOC files with in the Windows store app?

    Hi,
    I would like to display the PPT, PDF, XL, DOC files with in the Windows store app? is there any controls provided by Microsoft to view these files with in the app?
    Or
    Any workaround to achieve the desired functionality?
    Kindly provide your inputs if any one has.
    Regards
    Prasad

    Hi Prasad,
    As I know currently there is no in-build functionality to display the PPT, XLS or DOC file directly on the Windows Store App, but you can always open these files by
    Launcher class
    However a good news is we can display PDF on Windows Store App by
    Windows.Data.Pdf class, see this for more information:
    https://code.msdn.microsoft.com/windowsapps/PDF-viewer-showcase-sample-39ced1e8/
    --James
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Opening .doc files with wrong program

    Hi *,
    first I've installed open office. A few month later I installed micorsoft office. After that I converted all office files. Everything was working fine. Now my mac forgot to open .doc files with ms word, he chooses oo word. I do'nt have these problems with .xls files.
    Where are the global settings that I can tell my mac to open .doc files with ms word (I will not use "open with" each time;-)
    Thanks in advance
    Michael
    Message was edited by: MichaelLudt

    Select the file. Do a "Get-Info" from the File menu. (command-I). In the drop down menu "open with" select the program and then confirm you want all files like these to open with that program.

  • Why can I no longer open .doc files with Word2011

    I can no longer open .doc files with Word 2011.  .docx files are not a problem.  Everything stops responding as soon as I try to open a .doc file and I have to do a manual reboot (by holding the power button down).  This seems to coincide with my update to Mavericks OSX.  I have Word version 14.3.9.
    A colleague of mine is having the exact same problem. 
    I tried repairing my disk permissions but this didn't help.
    Please advise.

    You may want to ask your Office for Mac question in the Office for Mac forums: http://answers.microsoft.com/en-us/mac?auth=1

  • How to associate 1997-2003 Word doc files with Word 2010?

    Hi
    I am surprised not to be able to find out how to associate word 1997-2003 Word files with Wrod 2010. The object is to have Word 2010 open the document when I click on the document. Many of my Word 1997-2003 documents were created using Word 2010.
    When I try to use the associations function in Windows 7 I cannot find the Word program. Checking "Properties" on the Word Icon leads to a program called "CVH.EXE" which does nothing when I try to open doc files with it.
    Thank you.
    David
    lifeform23

    Hi,
    From your description , I understand that you want to open the prior Word doc files  in Word 2010.
    You can refer to the KB article that resolve this issue:
    How to open and save Word, Excel, and PowerPoint 2007 or 2010 files in earlier versions of Office programs
    http://support.microsoft.com/kb/924074
    Sincerely,
    Harry 

  • AOL mail doesn't send .doc-files with Firefox

    When using Firefox AOL Mail doesn't send .doc-files. Instead a corrupted file with a different size is sent. Any other file type works aswell as sending .doc-files with other browsers works...

    I'm getting a similar problem. Snow Leopard Mail for me seems to be choking on large attachments - sending them, forwarding them, or even moving them from one IMAP folder to another.
    My mails are getting through, but it takes a long time and they are dragging the whole system to a crawl in the process.

  • Create new project files with uploaded word document

    How do I create a new project file with an uploaded word document.  I tried to follow the guidelines using the Robohelp PDF file but after I upload the word document, I cannot see it in the workspace.  Are there other steps to bring the document into Robohelp 9.  I am using the trial version and have never used Robohelp before.
    Thank you!

    I was finally able to fix my problem and I hope to publish this in as many pages as I can.  First I had the exact same issue.  My file was password protected (the one I used as a shell for a new project) spent two hours of work, went home and next
    day “Nothing” same errors.  Cannot open file etc. etc.  So after two hours searching the net I found this company that has a
    Project Repair Toolbox that is cloud based for FREE (no useless downloads).
    I went in > It asked me for the file that I had on my local drive > prompted me for the password and > BAM! the file opened right up.  Since it as viewer only I was able to at least begin re-typing the project plan which was small in nature.
     Check it out, hope it works for you. 
    http://www.project.repairtoolbox.com/

  • Download a .doc file from a servlet, problems with filters

              Hi! I put this post in an incorrect forum so I think this is the correct one. Hope
              anyone can help.
              We need some help in order to view a .doc file that we've stored into a blob column
              of some oracle table. The file is compressed using Zip classes and now what we
              want to do is:
              We have a web page with a link to a servlet that will read the blob, unzip the
              file and show it into a new web page with ms word.
              The problem appeared when we put some compression filters in our WL 6.1 SP3 and
              the result is always the same. When we tell IExplorer to save the file it works
              correctly but when we tell him to open the document it shows the "Open with..."
              window as if the content-type or any other header was incorrect.
              Here is part of the code:
              ....... if(mydoc!=null && mydoc.length>0){ res.setHeader("Content-Type", "application/msword");
              res.setHeader("Cache-Control","no-cache"); res.setHeader("Content-Disposition",
              "attachment;filename=\"mydoc.doc\"" ); if(isZIPPED == 1){ ByteArrayInputStream
              array = new ByteArrayInputStream(informe); ZipInputStream zip = new ZipInputStream(new
              BufferedInputStream(array)); ZipEntry entry; while((entry = zip.getNextEntry())
              != null){ int n; byte mydata[] = new byte[16384]; ServletOutputStream out = res.getOutputStream();
              while((n = zip.read(mydata, 0, 16384)) != -1){ out.write(mydata, 0, n); } } }
              ... So, what are we doing wrong?
              Any help will be much appreciated!! Thanks.
              

    problem dissapeared, no need anymore to solve this one.

  • New Bie - Starting with JSP and Servlets

    Hello fellow members,
    It's my pleasure to be a part of such a wonderful forum. Today, I am here to learn JSP, Servlets, and related tech/frameworks.
    I'd be thankful to any member who can guide me in the right direction.
    I have good working knowledge of Core java.
    I have a licensed copy of weblogic 9.2, though I have no idea how it works :).
    Looking forward for some good pointers to start with. If anyone can hand hold me and tell me exercises I should do every day, there is nothing like that. I can dedicate in excess of 6 hrs daily to learn these new technologies.
    Thanks in advance,

    Sonia_31 wrote:
    I planned to start with tomcat. Tomcat is a good choice.
    I am using my cousins laptop which already has BEA weblogic 9.2 installed. He used to work as software engineer. So I thought it was better start with weblogic, than going for something else.Apparently his company is using Weblogic.
    As I am serious about the whole thing weblogic is a better option. You have application servers and application servers. When I say that Weblogic is commonly only used in "real" production environments, I do not mean that "real" production environments only use Weblogic. You can use any self-respected application server to your taste. Either freeware or payware. That you're using a payware one to start with just made my eyebrows raise.
    Looking for some info to get started. I have downloaded the pdf you have mentioned and started studying. I'll post my questions soon.Good luck.

  • Converting an html file with jsp contents to a text file for download

    Hi guys,
    I'm currently having troubles with downloading a .jsp file to a doc file.
    The thing is i am able to download the desired file and make it as a .doc but when i open it with ms word 2007 i can only see the content of the html. The dynamic content generated from the database and reflected on the .jsp page that i suppose to download and convert to .doc file doesn't show.. I hope someone could help me... My servlet code is this:
    public class FileDownload extends HttpServlet
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    try
    String originalFileName="localhost:8080//Appsdev//reportresults1.jsp";
    File f=new File(originalFileName);
    System.out.println("THE 1st f:"+f);
              response.setContentType("application/octet-stream");
    response.setHeader("Content-Disposition", "attachment; filename=tryreport.doc;");
    response.setHeader("Cache-Control", "max-age=0");
    byte[] buf = new byte[1024];
    FileInputStream inStream = new FileInputStream(f);
    OutputStream outStream = response.getOutputStream();
    int sizeRead = 0;
    int size = 0;
    while ((sizeRead = inStream.read(buf, 0, buf.length)) != -1)
    outStream.write(buf, 0, sizeRead);
    size += sizeRead;
    inStream.close();
    outStream.close();
    catch(Exception e)
    e.printStackTrace();
    }

    Hi BalusC,
    sorry for the double post i'm newly registered and it's my first post before i was just reading other's threads.
    well last night while i was reading and researching for a solution a came across this.
    <%@ page language="java" contentType="application/msword"%> naturally for my other jsp pages, the contentType is text/html so when the page loads it display in the browser. But with application/msword when i direct the page to the jsp page that i want to download and set the contentType with that...it prompts a window like when you're downloading the one with the <open with and save as>. It works fine to, i was able to see the report that i have to download and it is formatted very much like what i am seeing on the browser. My only concern now is the file i am able to download is a .jsp file how could i change that to a .doc file and be able to see the same content like the one with the .jsp file that i have right now.... any help or examples would be greatly appreciated. I didn't use the servlet anymore because even though i am able to download there is no content the html parts only but iam able to change the extension for the file...thanks again! ^ ^

  • New Bie help with MySQL & servlet

    Hi,
    I am trying to execute a small action... some how my code does not work. All it shows is a blank page with no error....
    Can any one help me to optimize this code so that it works?
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    package oneword;
    import com.mysql.jdbc.Connection;
    import com.mysql.jdbc.Statement;
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    import java.util.Random;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    public class Register extends HttpServlet {
        private String name = null;
        private String emailID = null;
        private String nameDB = "jdbc:mysql://localhost:3306/register";
        private String mysqlUser = "root";
        private String mysqlPassword = "abc";
        private String mySqlJdbcDriver = "com.mysql.jdbc.Driver";
        private Connection conn = null;
         * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
         * @param request servlet request
         * @param response servlet response
         * @throws ServletException if a servlet-specific error occurs
         * @throws IOException if an I/O error occurs
        protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException, ClassNotFoundException, SQLException {
            response.setContentType("text/html;charset=UTF-8");
            PrintWriter out = response.getWriter();
            name = request.getParameter("_name");
            emailID = request.getParameter("_email");
            try {
                Random generator = new Random();
                int activationPassword = generator.nextInt(100000);
                Class.forName(mySqlJdbcDriver);
                conn = (Connection) DriverManager.getConnection(nameDB,mysqlUser,mysqlPassword);
                Statement statement = (Statement) conn.createStatement();
                String sqlCommand = "INSERT INTO userdata(name, email, validation, " +
                        "banned, activatepassword, password)values("+name+", "+emailID+", 0, 0,"+activationPassword+", 'ddd')";
                statement.executeQuery(sqlCommand);
                out.println(name);
                out.println("<br>"+emailID);
                out.println("rows affected:");
                conn.close();
            } catch (SQLException ex) {
            // handle any errors
            System.out.println("SQLException: " + ex.getMessage());
            System.out.println("SQLState: " + ex.getSQLState());
            System.out.println("VendorError: " + ex.getErrorCode());
            } finally {
                out.close();
        // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
         * Handles the HTTP <code>GET</code> method.
         * @param request servlet request
         * @param response servlet response
         * @throws ServletException if a servlet-specific error occurs
         * @throws IOException if an I/O error occurs
        @Override
        protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
            try {
                processRequest(request, response);
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(Register.class.getName()).log(Level.SEVERE, null, ex);
            } catch (SQLException ex) {
                Logger.getLogger(Register.class.getName()).log(Level.SEVERE, null, ex);
         * Handles the HTTP <code>POST</code> method.
         * @param request servlet request
         * @param response servlet response
         * @throws ServletException if a servlet-specific error occurs
         * @throws IOException if an I/O error occurs
        @Override
        protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
            try {
                processRequest(request, response);
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(Register.class.getName()).log(Level.SEVERE, null, ex);
            } catch (SQLException ex) {
                Logger.getLogger(Register.class.getName()).log(Level.SEVERE, null, ex);
    }Thank you

    A blank page usually indicate that an exception is been thrown but cannot be displayed because the response is already started/committed/processed. Just read the appserver's logs as usual for the details.
    Your servlet class does way too much. You're mingling all the processing steps together in one class. This is simply asking for trouble. Use a DAO class for accessing the DB. Use a JSP file for presentation. Use a business object to process the input/output data. Use a servlet for controlling the request. To start off, you may get some ideas out of this article and the JSP/Servlet follow-up: [http://balusc.blogspot.com/2008/07/dao-tutorial-data-layer.html].
    Oh, your JDBC code is not safe against SQL injection attacks either.

  • How to open a .DOC file with MS-Word ?

    Hye fellow Java freaks,
    I have made an application to upload .DOC and .RTF files to the server using servlets and the Jakarta Commons FileUpload package.
    The files are uploading successfully.
    Now, I want to place a link to the most recently uploaded file and then, on clicking that link, I want the file to open not in the browser, rather with MS-Word.
    What is the servlet code that I should implement to accomplish this ?
    Any suggesions ?
    Thanx in advance.

    I think this is a client-side issue - how the browser chooses to deal with the .doc file it receives.
    You can 'save as' and then open the file by hand.
    --Jon                                                                                                                                                                                                                                                                                                                               

Maybe you are looking for

  • How can i get an itunes gift code?

    hi everyone i bought a refurbish mac and i got a code to upgrade to os lion but i live in trinidad west indies and my country is not on the list, how can i redeem this upgrade?

  • Problem capturing from a Sony DVR-HC51e

    Hi there, as it says, I can't seem to get FCE to recognise my handycam. It's a Mini DV PAL camera and is connected by a 4 pin to 9 pin firewire (it's the only wire I could find to fit the port). I've went through all the DV settings n the Easy Setup

  • [solved] Pulseaudio, multiple users, audio group?

    Hello! I'm trying to get pulseaudio working for multiple users. According to the pulseaudio documentation, no user should be in the audio group which should theoretically make it work. I think I've also seen that information in a file distributed wit

  • Using STORED PROCEDURE IN ORACLE FOR LOGIN AND UPDATES

    HI, I am trying to use oracle stored procedure to use it for LOGIN[AUTHENTICATION] purpose and also to update table values in the database. anyone has and idea as to how i can accomplish this . Please send in your replies. Thank you.

  • Apache 2.2.2

    Hello, Maybe someone can help me. I need to upgrade the Apache Server in a Linux RH4. So my question is how to migrate to Apache 2.2.2 and keep the modplsql working? The connection to the apex database that is... From there I intend to move and integ