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! ^ ^

Similar Messages

  • Want to display the contents of a text file in a jsp

    hi
    i am new to jsp, i want to display the contents of a text file in a jsp file ,whenever jsp file is loaded from browser.
    -thanx

    i had come up with the code
    <!-- form.jsp -->
    <%@ page import="java.io.*, java.lang.*" %>
    <%@ page language="java" %>
    <html>
    <head>
    <title>Display</title>
    </head>
    <body>
    <%
    String sample[100];
    String line;
    %>
    <%! int i=0; %>
    <%!File f1 = new File("c:\\file.txt"); %>
    <% try { %>
    <%!FileReader fi = new FileReader(f1); %>
    <% } catch(FileNotFoundException io) { } %>
    <%!BufferedReader in = new BufferedReader(fi); %>
    <%
    while((line=in.readLine())!= null)
    sample= line;
    i++;
    in.close();
    %>
    i will display sample here
    </body>
    </html>
    but i am getting error
    display_jsp.java:16: unreported exception java.io.FileNotFoundException;
    must be caught or declared to be thrown
    FileReader fi = new FileReader(f1);
    ^
    plz help
    -thanx

  • Upload files with international content

    I want to upload files with international content(many languages), from
    a single JSP. Any ideas?
    thanks,
    M.

    Hi Marco,
    I dont know transaction CV02N. But if this application uses standard function modules like GUI_UPLOAD it should work with ITS. A special configuration should not be required as long as the files have a size up to 5 MB. If they are larger it might be required to adjust the size of the request container MaxReqSize. Dont forget that Java has to be activated to let webgui access the filesystem.
    Regards,
    Klaus

  • How to convert content of a Text file to String?

    Hi,
    I need to read the content of a text file and convert it into String and display it on to a JSP file.
    But the codings below don't work. Please advise me on how can i display the text file content.
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    File adCheck = new File("list.txt");
    fis = new FileInputStream(adCheck);
    int Length = adCheck.length();
    byte arr[] = new byte[Length];
    int dataRead = 0;
    int totalData = 0;
    while(totalData <Length)
         dataRead = fis.read(arr,totalData,Length);
         totalData += dataRead;
    String Content = new String(arr);//byte array converted to String
    arr = null;

    Take a BufferReader:
    BufferedReader read = new BufferedReader(new FileReader("c:\test.txt");
    String temp = read.readln();
    You can make loops etc. Adding new Strings to an ArrayList,
    adding Strings etc....

  • Can't create dynamic html elements with jsp????? important

    Hi All,
    I am having problem creating dynamic html elements with jsp tags, i have tried to use EL and java scriplet, both of them don't work.
    i am trying to create dynamic menu in my "rightMenu.jspf", based on, if user has logged in or not.
    some like this!
    <jsp:if test ="${validUser == null}">
    some simple text menu here
    </jsp:if>
    but it is not working. it simply loading all and images with in statement, regardless of whether user has logged in or not. i think some how if statement is not working properly.
    "validUser" is a session bean, which is not creating at this point, it will created when user will log in successfully. and also this session bean does not exist at the page, where i am trying to check that .
    Is there any way to create dynamic values in jsp. It is really important, is there any body who help me in this matter. i would be really grateful.
    zaman

    hi jaspre,
    thanks for replying me. you know what, is it not something wrong with web.xml file. i remember once, i deleted some from there, a property with "*.jsp". i can't remember what exactly was it though.
    all if statements works on files ending with extension ".jsp" but don't work only on with extension ".jspf". there must be to do with this.
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <servlet>
    <servlet-name>ValidateServlet</servlet-name>
    <servlet-class>ValidateServlet</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>ValidateServlet</servlet-name>
    <url-pattern>/ValidateServlet</url-pattern>
    </servlet-mapping>
    <servlet>
    <servlet-name>dwr-invoker</servlet-name>
    <servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>
    <init-param>
    <param-name>debug</param-name>
    <param-value>true</param-value>
    </init-param>
    <init-param>
    <param-name>pollAndCometEnabled</param-name>
    <param-value>true</param-value>
    </init-param>
    </servlet>
    <servlet-mapping>
    <servlet-name>dwr-invoker</servlet-name>
    <url-pattern>/dwr/*</url-pattern>
    </servlet-mapping>
    <session-config>
    <session-timeout>
    30
    </session-timeout>
    </session-config>
    <welcome-file-list>
         <welcome-file>
    main.jsp
    </welcome-file>
    </welcome-file-list>
    </web-app>
    if any one can figure it out. i would be grateful.
    zaman

  • How to modify the contents of a text file stored along with a midlet

    Hi,
    I have been developing a application in j2me wherein i need to first read the contents of the text file stored along with the midlet and later erase the existing content and update it with some text.
    I was able to read the file in the following manner
    InputStream is = getClass().getResourceAsStream("myfile.txt");
    Now i need to erase the contents and then update it the new content, how do i do it. Kinldy please help me out. It is very urgent.
    Thanks

    Didn't you hear me the first time?
    http://forum.java.sun.com/thread.jspa?threadID=701360&messageID=4068435#4068435

  • When i convert a word file with a hyperlinks to a PDF file it doesn't work ?? thanks in advance for helping me

    when i convert a word file with a hyperlinks to a PDF file it doesn't work ?? thanks in advance for helping me

    using microsoft word.
    the hyperlink doesn't work in the pdf file (adobe reader).
    adobe reader xi.
    my operating system windows 8.1.
    the attached screen is appeared.

  • To create 3 diff files with same content but with diff names in same target

    Hi SapAll.
    i have got a a requirement where pi need to create 3 different files with same content but with different names under same target from a single Idoc.
    its an IDOC to 3 File Inteface.
    can any body help me in providing the differnt solutions for this without use of any script executions.
    will be waiitng for response.
    regards.
    Varma

    > i want to use only one communication channel to produce 3 different file names with same content ,so here i should use only one message mapping in 3 operation mappings .
    This is not possible to produce 3 different file names with single CC. You have to use 3 different CCs. unless you have going to use some other trick e.g some script to rename the file etc..
    As I suggested in my previous reply use Multi-Mapping Or create 3 different Interface Mappings (by using the same MM).
    Note: You have to create 3 different Inbound Message Interfaces (you can use the same Inbound Message Type) otherwise while creating the 3 Interface Determination it won't allow because of same Outbound & Inbound Message Interface. It will simply say Interface alreday exists..
    So, just use the Multi-Mapping which is best solution in my opinion, because the benefit of using multi-mapping are:
    1. You have to create only single Message Mapping
    2. Single Interface Mapping
    3. Single Receiver Determination
    4. Single Interface Determination
    5. 3 Receiver CCs (3 you have to use in any case)
    6. Performance wise it is good (read the blog's last 2 para)
    7. And last but not the least easy to maintain the scenario.

  • Creating Player Problem from file with unknown content

    Hi,
    I need to create Player from video file with unknown content ie. from file "test.dat"
    try{
    MediaLocator ml = new MediaLocator(new URL("file:///D:/test.dat"));
    Player p = Manager.createPlayer(ml);
    catch(NoPlayerException npe){}
    catch(MalformedURLException mUe){}
    catch(IOException ioe){}
    throws NoPlayerException
    Pleeeease Help!!!

    I think it should be : "file:D:/test.dat" But i do believe that it will not work with a .dat file...

  • Cannot print PCL file with graphical content

    If I try to print a PCL file with graphical content using lp then the output is corrupt on a network printer. I've tracked the problem down to the netpr program - which seems to be performing some sort of filtering on the data. Does anyone know how the flags work for netpr - or know of a work around?

    Assuming you are running 10.10.2 and not the ancient 10.0.2, can you tell us what printer and printer driver you are using? How is the printer connected to the computer (network, usb)? See if you can delete the Reader preference files? Years ago I resetting the printer subsystem would sometimes cure a problem like this.

  • How do I convert my Voice Memo from iPhone 5s to a text file?

    How do I convert my Voice Memo from iPhone 5s to a text file?

    If you have Evernote, you could try quicktate.   http://www.quicktate.com
    I convert voice memos on my Mac using the Dictation feature:
    Open TextEdit on a new document
    Enable  Dictation & Speech enabled the System Preferences.
    Press the fn-key twice
    Play the voice memo on the iPhone and let the  Mac listen to it using the internal microphone with TextEdit open on a new document.
    Press the fn-key twice, to finish Dictation.  You will only see the transcribed text, when Dictation has finished.

  • How to read the content of a text file (by character)?

    Guys,
    Good day!
    I'm back just need again your help. Is there anyone knows how to read the content of a text file not by line but by character.
    Please help me. Thank you so much in advance.
    Jojo

    http://java.sun.com/javase/6/docs/api/index.html
    package java.io
    InputStream.read(): int
    Reads the next byte of data from the input stream.
    Implementation:
    InputStreamReader
    An InputStreamReader is a bridge from byte streams to character streams: It reads bytes and decodes them into characters using a specified charset. The charset that it uses may be specified by name or may be given explicitly, or the platform's default charset may be accepted.

  • How to store the contents of a text file directly in to a clob field

    Hi All,
    Could anyone help me to store the contents of a text file (*.txt,*.xml etc)directly in to a clob field.
    Thanks in advance
    Jayaram.

    One way is to use sqlloader. Three files are used. A control file, an xml data file, and a file with the path of the xml data file. Here's the control file. It reads load.file, which is the file with the path of the xml data file. It names the path ext_path, and inserts the xml into field xml_field.
    CONTENTS OF CONTROL FILE:
    load DATA
    INFILE 'load.file'
    APPEND
    INTO TABLE xml_table
    ( ext_path FILLER CHAR(13),
    "XML_FIELD" LOBFILE(ext_fname) TERMINATED BY EOF
    CONTENTS OF FILE LOAD.FILE:
    /tmp/load.dat
    The xml is in the file /tmp/load.dat.
    null

  • How do i split content from the text file using tab and spaces...?

    Hi.. Just want to ask help to all the experts. Im new in java and i have this problem on how to split the contents of the text file. ill show you the contents in order to let you see what i mean.
    FileName: COL.txt
    AcctNo AcctName Primary Secondary Status Opendate
    121244 IPI Company Noel Jose Active 12/05/2007
    As you can see the content i want to split it per column.. Please help me

    Jose_Noel wrote:
    Hi prometheuzz,
    What do you mean by one thread...?You created two threads* with the same question in it. That way, people might end up giving you an answer that has already been posted in your other thread: thus wasting that person's time.
    Just don't create multiple threads with the same question please.
    * a thread is a post here at the forum

  • To add meta tags, you open your published .html pages with TextEdit or any other text editor and modify as required. You have to do redo it each time you republish. Ihow do I do this? I need step by step instructions

    To add meta tags, you open your published .html pages with TextEdit or any other text editor and modify as required. You have to do redo it each time you republish. I need step by step instructions on how to accomplish this  please .

    Rage Sitemap Automator and iWeb SEO Tool are two different applications.
    Use SEO Tool to add the title tag and meta description. These need to be added to the html file for every page of your website. SEO Tool stores all these so that when you republish you only need to add tags to any new pages and click the re-apply button to refresh the existing ones.
    Once you have added. refreshe the tags with iWeb SEO Tool and uploaded the files with your FTP application, then open the site in Sitemap Automator and create and upload a new sitemap.
    Once you have set up accounts with Google, Yahoo and Bing, verified your site with each and submitted a sitemap, on subsequent publishing Sitemap Automator will resubmit the sitemap with one button click. It will also notify Ask.com whch doesn't require an account since you can add your domain name to this URL to ping them...
    http://submissions.ask.com/ping?sitemap=http%3A//www.domain.com/sitemap.xml

Maybe you are looking for