How to send a text file as jsp response

Hi
I want to send a text file/or other file as jsp response ..How to do it..
Pls tell me if any body knows about it..
thanks

Hmmm im no expert but i think you would have to convert it to a byte array and use OutputStream with the response ... not sure ...like i said, im no expert

Similar Messages

  • How to send a text file to a printer?

    Hi, I'm in dark on how to send a text file to a printer through Java Stored Procedure.
    Here are what I tried so far (OS: win 2000, Oracle: 817 or 9i2):
    1, Enable DOS command in Java Stored Proc. and try to send PRINT command there:
    public static String Run(String Command){
    try{
    Runtime.getRuntime().exec(Command);
    System.out.println("Command: " + Command);
    return("0");
    catch (Exception e){
    System.out.println("Error running command: " + Command +
    "\n" + e.getMessage());
    return(e.getMessage());
    public static void main(String args[]){
    if (args.length == 1)
    Run("print /D:\\\\enterprise\\john " + args[0]);
    else System.out.println("Usage: java OSCommand filename");
    PL/SQL wrapper:
    CREATE OR REPLACE FUNCTION OSCommand_Run(p1 IN VARCHAR2) RETURN VARCHAR2 AUTHID CURRENT_USER AS LANGUAGE JAVA NAME 'OSCommand.Run(java.lang.String) return java.lang.String';
    SQL command:
    //print /D:\\machine\printer test.txt
    I loaded the Java Stored Procedure into SYSDBS account, it failed silently, even though piece of code works fine in external JVM.
    2, Use filePrinter:
    public static String print(String printString) {
    try{
    String printerUNC = "\\\\machine\\printer";
    FileWriter fw = new FileWriter(printerUNC);
    PrintWriter pw = new PrintWriter(fw);
    pw.println(printString);
    fw.close();
    return "OK";
    }catch(Exception e){
    e.printStackTrace();
    return "Exception: " + e.getMessage();
    public static void main(String[] args) {
    try{
    String printerUNC = "\\\\machine\\printer";
    String printString = "Hello World";
    FileWriter fw = new FileWriter(printerUNC);
    PrintWriter pw = new PrintWriter(fw);
    pw.println(printString);
    fw.close();
    }catch(Exception e){e.printStackTrace();}
    I loaded it into SYSDBS too, and tried with this:
    SQL> select MY_PRINT.PRINT('HELLO from Oracle') from dual;
    MY_PRINT.PRINT('HELLOFROMORACLE')
    Exception: No such file or directory
    SQL> show user
    USER is "SYS"
    It works in external JVM too.
    What's wrong with this?
    Thanks for any help in advance,
    Charles

    Avi:
    Thanks for your response!
    I put the java code in SYS, 'cause I assume that account has max privilege. If the test is successful, I will move that to some user schema and then to deal with those privilege settings... But I'm unlucky.
    I checked Ask Tom, this is what I got from http://asktom.oracle.com/pls/ask/f?p=4950:8:1619723::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:38012348052,%7Bprinter%7D:
    ... Print file from PL/SQL ...
    If you are using Oracle8i, release 8.1 -- much can be done with Java. java
    would be able to print directly from the server.
    Looks like using Java to print out file is better than PL/SQL. But there's no more hint there! And, no new question can be asked there today either...
    I'm wondering whether we can create a socket to a printer and send the characters there directly... Anyone has experience on this?
    Thanks for all the help in advance,
    Charles

  • How to send a text file over a LAN?

    Hi:
    I am working on a program (web app using a servlet), that produces a text file with Key / Value pairs ex) NAME
    joe
    CITY
    los angeles
    I want to send the text file over an intranet (LAN) to another pc and store it in the C:\temp directory of the receiving computer.
    Is it best to use the Networking package? Any idea on tutorials or code samples to help assist me? (I posted on Servlet Technology forum; nobody answered though...thanks for any thoughts.

    one way cud be that u write a program to open a port on the computer u want to store and make that program save on the required directory. then u can send a simple file in byte format over it. but doing this only wud b unsafe as others wud also hav the access. wat u cud do to prevent is to put some kind of password so that first u authenticate to server b4 u pass on the file.
    bye
    jods

  • How to send a text file attachment through mail in ECC 6.0

    Hi Friends,
    As per the requirement, I need to send a ALV report result as text file attachment to user in ECC 6.0 . I know how to do in 4.6C version. But the same code is not working here in ECC 6.0.
    Generally to get the data in new row in the text file we use below code in 4.6c.
    data: c_value type x value ' 0D '.
    concatenate c_value itab-line into itab-line.
    By using above code, we get each row of the itab in a new line in text file.
    Same code is not working in ECC6.0 as it is not supporting  to concatenate bytes with characters. Getting the error like " field c_value should be diclared as type C or I or N or T or P"
    Even I have used function module NLS_STRING_CONVERT_TO_SYS to convert hexa to char. It is converting the value' 0D' to ' # '. But it is not working.
    Could you please suggest me that how can get each row of itab as a new line in text file in ECC 6.0.
    Itab value:
    abcdefdfldjfñlkdsjfñldsjfdsñljñla
    fdsljfñldskjfldsñkjfñldsjfñldsajñld
    vcxusfcxusfcusafcxusafcusafcdsauc
    Actual result currently coming in text file:
    abcdefdfldjfñlkdsjfñldsjfdsñljñlafdsljfñldskjfldsñkjfñldsjfñldsajñldvcxusfcxusfcusafcxusafcusafcdsauc
    Expected result in text file:
    abcdefdfldjfñlkdsjfñldsjfdsñljñla
    fdsljfñldskjfldsñkjfñldsjfñldsajñld
    vcxusfcxusfcusafcxusafcusafcdsauc
    Please do the needful.
    Thanks
    Kumar

    hi,
    Try this function Module
    CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1 '
    *example code
    ******* Create Message Body Title and Description****************
      i_objtxt = 'test with pdf-Attachment!'.
      append i_objtxt.
      describe table i_objtxt lines v_lines_txt.
      read table i_objtxt index v_lines_txt.
      wa_doc_chng-obj_name = 'smartform'.
      wa_doc_chng-expiry_dat = sy-datum + 10.
      wa_doc_chng-obj_descr = 'smartform'.
      wa_doc_chng-sensitivty = 'F'.
      wa_doc_chng-doc_size = v_lines_txt * 255.
    **** Main Text*****************************
      clear i_objpack-transf_bin.
      i_objpack-head_start = 1.
      i_objpack-head_num = 0.
      i_objpack-body_start = 1.
      i_objpack-body_num = v_lines_txt.
      i_objpack-doc_type = 'RAW'.
      append i_objpack.
    **** Attachment (pdf-Attachment)*************
      i_objpack-transf_bin = 'X'.
      i_objpack-head_start = 1.
      i_objpack-head_num = 1.
      i_objpack-body_start = 1.
      i_objpack-body_num = v_lines_bin.
      i_objpack-doc_type = 'PDF'.
      i_objpack-obj_name = 'smartform'.
      concatenate i_objpack-obj_name i_objpack-doc_type into
    i_objpack-obj_descr separated by '.'.
    *  I_OBJPACK-OBJ_DESCR = 'test'.
      i_objpack-doc_size =  v_lines_bin * 255 .
      append i_objpack.
    * Länge des Attachment ermitteln
      clear i_reclist.
      i_reclist-receiver = 'email address'.
      i_reclist-rec_type = 'U'.
      i_reclist-express = 'X'.
      data: tab_lines like sy-tabix.
      describe table i_objbin lines tab_lines.
      append i_reclist.
      call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'
        exporting
          document_data              = wa_doc_chng
          put_in_outbox              = 'X'
          commit_work                = 'X'
        tables
          packing_list               = i_objpack
          object_header              = wa_objhead
          contents_bin               = i_objbin
          contents_txt               = i_objtxt
          receivers                  = i_reclist
        exceptions
          too_many_receivers         = 1
          document_not_sent          = 2
          document_type_not_exist    = 3
          operation_no_authorization = 4
          parameter_error            = 5
          x_error                    = 6
          enqueue_error              = 7
          others                     = 8.
      if sy-subrc <> 0.
        write:/ 'Error When Sending the File', sy-subrc.
      else.
        write:/ 'Mail sent'.
      endif.

  • How to create a text file from jsp?

    In JSP, what is the command to create a text file and dump a variable in it?

    You mean StringBuffer?

  • How to download a text file using jsp i

    I want to provide download facility in jsp page.
    if i have exe download is working . If I have a text / html file it is just displaying I want to make it download How to do it?
    regards
    subrahmanayma

    If you want to get an "Save as" dialogue, then you need to set the content-disposition in the header to "attachment". The default value is "inline".
    Best solution is to create kind of a FileServlet and let it stream the right file as a download to the client. You may find the downloadFile() snippets at the bottom of this article useful: http://balusc.xs4all.nl/srv/dev-jep-pdf.html Put it in a FileServlet and call it using for example .

  • How to send a text file or a excel file as an attachment in workflow

    Hi all,
    I would like to send an e-mail containing an attachment in text or excel format in oracle workflow.Can anyone tell me or give me an example as how it can be done.
    My e-mail id is [email protected]
    Thanks in Advance.
    Regards,
    pavan

    Hi,
    I am embedding a CLOB message document attribute to my Notification
    Message Body.
    Everything works fine when I check my notifications in the "workflow worklist"
    i.e. Oracle Apps. <Notifications> tab.
    but the emails are not going to the users and below message is displayed in the
    status monitor. (eventhough it displays below error - I can able to respond the notifications using the worklist and can able to COMPLETE the workflow process
    successfully)
    Please help me to resolve the below error, so that the Same notification which I am able to see using the workflow worklist should be sent to the user in email as embedded text.
    NOTE: there is no problem with the Package XXDB_OKC_CONTRACTS_WF_PKG, as it is not changed and I even verified it before and after this error that this package is indeed in VALID status.
    Workflow Errors: XXDBCAPR, SDA-10314
    Failed Activity Send Approve_Reject Responce Notification
    Activity Type Notice
    Error Name WF_ERROR
    Error Message [WF_ERROR] ERROR_MESSAGE=3835: Error '-20002 - ORA-20002: 2018: Unable to generate the notification XML. Caused by: 2020: Error when getting notification content. Caused by: ORA-04061: existing state of has been invalidated ORA-04061: existing state of package "APPS_FND.XXDB_OKC_CONTRACTS_WF_PKG" has been invalidated ORA-04065: not executed, altered or dropped package "APPS_FND.XXDB_OKC_CONTRACTS_WF_PKG" ORA-06508: PL/SQL: could not find program unit being called Wf_Notification.GetAttrClob(18841, MESSAGE_BODY, text/html) Wf_Notification.oldGetAttrC' encountered during execution of Generate function 'WF_XML.Generate' for event 'oracle.apps.wf.notification.send'. ERROR_STACK= WF_MAIL.GetLOBMessage3(18841, WFMAILER, 2020: Error when getting notification content. Caused by: ORA-04061: existing state of has been invalidated ORA-04061: existing state of package "APPS_FND.XXDB_OKC_CONTRACTS_WF_PKG" has been invalidated ORA-04065: not executed, altered or dropped package "APPS_FND.XXDB_OKC_CONTRACTS_WF_PKG" ORA-06508: PL/SQL: could not find program unit being called Wf_Notification.GetAttrClob(18841, MESSAGE_BODY, text/html) Wf_Notification.oldGetAttrClob(18841, MESSAGE_BODY, text/html) WF_NOTIFICATION.GetFullBody(nid => 18841, disptype => text/html) WF_MAIL.GetLOBMessage3(nid => 18841, r_ntf_pref => MAILHTML), Step -> Getting text/html body) WF_XML.GenerateDoc(oracle.apps.wf.notification.send, 18841) WF_XML.Generate(oracle.apps.wf.notification.send, 18841) WF_XML.Generate(oracle.apps.wf.notification.send, 18841) Wf_Event.setMessage(oracle.apps.wf.notification.send, 18841, WF_XML.Generate) Wf_Event.dispatch_internal()
    Error Stack
    thanks,
    Shashi
    NOTE: there is no problem with the Package XXDB_OKC_CONTRACTS_WF_PKG, as it is not changed and I even verified it before and after this error that this package is indeed in VALID status.

  • How to send a text file to printer in Java 1.3.1

    Please don't sujest 1.4. My users run it on 1.3

    I don't guarantee that this works in 1.3 - I really just don't know.
    But what I did the last time I had to print text was
    instantiate a JEditorPane.
    editorPane.setText(text);
    instantiate a DocumentRenderer
    renderer.print(editorPane);

  • How to call text file in jsp

    Hi all,
    I can call html or jsp file from jsp file, but how can I call text file in jsp, I put my text file same lever asmy jsp file it don't work!
    where I should put the text file??
    thank you

    mary,
    since you knew the file name ,when clicked in name send to server,read the file and write to servlet outputstream.
    I think this would help you.
    If anything wrong in mycode ..forums will help you further
    BufferedInputStream bis=null;
    BufferedOutputStream bos=null;
    int bytesRead=0;
    byte buff[]=new byte[1024];
    File f=new File(test.txt);
    try{
         bis= new BufferedInputStream(new FileInputStream(f));
         bytesRead=bis.read(buff,0,buff.length);
         if(bytesRead!=-1){
              // create a BufferedOutputStream from ServletOutputStream
              bos=new BufferedInputStream(response.getOutputStream());
              do{
                   bos.write(buff,0,bytesRead);
              }while((bytesRead=bis.read(buff,0,buff.length))!=-1)
    }catch(Exception e){
         ////error handling
         }

  • How to zip a text file and send as email attachment in SAP version 4.6c?

    Hi Guru,
    How to zip a text file in SAP version 4.6c which doesn't have class CL_ABAP_ZIP?
    Please help.
    Thanks & Regards,
    Ari

    Hi,
    Try this link
    [http://sap.ittoolbox.com/groups/technical-functional/sap-dev/sapr3dev-zip-file-from-sap-1707099?cv=expanded]
    Cheers,
    Surinder

  • Sending a text file Client/Server problem

    Hi,
    I have two java classes (A.java and B.java). i would like to send the text file (something.txt) from A to B. Can somebody please show me how to do so? I know it is incomplete, but i really need help since im new to this. I dont know how to send and how to accept the file. Here is what i have so far:
    import java.net.*;
    import java.io.*;
    import java.lang.*;
    public class A {
            private static String hostname;                  //host name
            private static final int portA = 1111;           //source port number
            private static int portB;                        //destination port number
            private static ServerSocket s;
            private static Socket socket;
            private static BufferedReader br;    
            String fileName = "something.txt";
            public A () {
            public static void send() {
                    System.out.println("Send method");
                    try {
                        System.out.print("> Enter Hostname: ");
                     hostname = br.readLine();
                     System.out.print("> Enter Port Number: ");
                        portB = Integer.valueOf(br.readLine()).intValue();
                catch(IOException e){}
            public static void main(String args[]) throws IOException {
    import java.net.*;
    import java.io.*;
    import java.lang.*;
    public class B {
            private static String hostname;                  //host name
            private static final int portB = 2222;           //source port number
            private static ServerSocket s;
            private static Socket socket;
            private static BufferedReader br;    
            public B () {
            public static void recieve() {
                 //code to recieve the text file here?
            public static void main(String args[]) throws IOException {
    }I really appriciate any code to help me out. Thanks

    Check out the link shown below:
    http://forum.java.sun.com/thread.jsp?forum=33&thread=66616
    If that doesn't answer your question, search this site for Upload
    ;o)
    V.V.

  • Sending EMail "Text-File" from Application Server!

    Hi Experts,
    how can I sending a Text-File from Application Server via Email?
    Is there existing a Function Modul?
    With Kind regards
    Ersin
    Moderator message: sending emails = FAQ, please search before posting.
    Edited by: Thomas Zloch on Nov 25, 2010 4:23 PM

    STF (Search the forum)!  This type of question has been asked...and answered....many times.

  • Sending a text file

    hi
    please can any one tell me if I want to send a text file residing on my mobile to another mobile using SMS how is it possible
    I already hv a j2me application tht can send a text message.
    I want a program tht will send this whole .txt file and the other end receives it as a text file
    thanx
    forumm

    hi
    can I split a text file and reassemble it using j2me
    or I send the text in the file using the usual sms
    and if I need to split the text file please can u give me some reference where I can find information about how to do that
    thanx a ton
    Forum

  • How to attach a text file as an attachment to email message?

    Hello Everybody,
    I have a .csv file, in which details about emp-id, emp-name, e-expenses for Reimbursement and email address are stored.
    My application reads this .csv file, and sends a mail to each employee with his id, salary details in text format. (by changing content type to "text/plain") The code is working fine. But,
    My problem is:
    The message is sent as message body to the end user.
    The end user / the person who receives this mail will not be a technical person. So,
    1) If he trys to take a print out of this e-mail, He get only half of it.(as no. of colums will be more than paper size).
    2) I am finding alignment problem. IF employee name is too big, other columns will shift to right and data will not be exactly under column header. (it is going in zig zag way)
    So, I thought sending text file with all the details as an attachment might do well.
    But, I don't know how to attach a text file to email-message body.
    code
    try
                   {               String s1="";
                                  File f1 = new File(the path);
                                  FileInputStream fstream = new FileInputStream(f1); //new
                                  BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
                                  int count=0;
                                  while((s1=br.readLine())!=null )
                                                 count++;
                                                 //out.println("within while loop "+count);
                                                 StringTokenizer st = new StringTokenizer(s1,",");
                                                 if ((st.hasMoreTokens())&&(count>1))
                                            String a=st.nextToken().trim();
                                                 String b=st.nextToken();
                                                 String c=st.nextToken();
                                                 String d=st.nextToken();
                                                 String e=st.nextToken();
                                                 String f=st.nextToken();
                                                 String g=st.nextToken();
                                                 String h=st.nextToken();
                                                 String i=st.nextToken();
                                                 String j=st.nextToken();
                                                 String k=st.nextToken();
                                                 String l=st.nextToken();
                                                 String m=st.nextToken();
                                                 String n=st.nextToken();
                                                 String o=st.nextToken();
                                                 String p=st.nextToken();
                                                 String q=st.nextToken();
                                                 String mail=st.nextToken();
                                                 String s=st.nextToken();
                                                 //out.println("b="+b+"c="+c+"d="+d+"e="+e+"f="+f+"mail="+mail);
                                                 %>
    <%
                                            String to =mail;
                                                 String from =request.getParameter("fromadd");                                        
                                                 String subject ="Statement of Expenses";
                                                 String smtp ="mail.xxxxxxxxxx.com";
                                                 String message="";                                        
                                                 message=message.concat("EMP ID");
                                                 message=message.concat("     ");
                                                 message=message.concat("Name");
                                                 message=message.concat("          ");
                                                 message=message.concat("Dept No.");
                                                 message=message.concat("     ");
                                                 message=message.concat("Acc No.");
                                                 message=message.concat("     ");
                                                 message=message.concat("*****************************************************************************************");     
                                                 message=message.concat(a);
                                                 message=message.concat("     ");
                                                 message=message.concat(b);
                                                 message=message.concat("          ");
                                                 message=message.concat(c);
                                                 message=message.concat("     ");
                                                 message=message.concat(d);
                                                 Properties props = System.getProperties();
                                                 // Puts the SMTP server name to properties object
                                                 props.put("mail.smtp.host", smtp);
                                                 // Get the default Session using Properties Object
                                                 Session session1 = Session.getDefaultInstance(props, null);
                                                 // Create a New message
                                                 MimeMessage msg = new MimeMessage(session1);
                                                 // Set the From address
                                                 msg.setFrom(new InternetAddress(from));
                                                 // Setting the "To recipients" addresses
                                            msg.setRecipients(Message.RecipientType.TO,InternetAddress.parse(to, false));
                                            /* // Setting the "cc recipients" addresses
                                            msg.setRecipients(Message.RecipientType.CC,InternetAddress.parse(cc, false));
                                            // Setting the "Bcc recipients" addresses
                                            msg.setRecipients(Message.RecipientType.BCC,InternetAddress.parse(bcc, false)); */
                                            // Sets the Subject
                                            msg.setSubject(subject);
                                            // set the meaasge in HTML format
                                            msg.setContent(message,"text/plain");
                                            // Set the Date: header
                                            msg.setSentDate(new java.util.Date());
                                            // Send the message
                                            Transport.send(msg);
                                            // Display Success message
                                            result =result.concat("<tr><td>"+b+"</td>"+"<td>"+to+"</td></tr>");
                                                      }//end of if of hasmore element
                                       }// end of while loop
                        out.println(result);                    
    }catch(Exception e)
                        // If here, then error in sending Mail. Display Error message.
                        result="Unable to send your message";
                        out.println("e="+e);
    Any help will be appreciated.
    Thanks and regards.
    Ashvini

    <html>
    <p>
    MimeBodyPart mbp1 = new MimeBodyPart();
    mbp1.setText("Your Messages");
    MimeBodyPart mbp2 = new MimeBodyPart();
    FileDataSource fds = new FileDataSource("Your Attachments");
    mbp2.setDataHandler(new DataHandler(fds));
    mbp2.setFileName(fds.getName());
    Multipart mp = new MimeMultipart();
    mp.addBodyPart(mbp1);
    mp.addBodyPart(mbp2);
    msg.setContent(mp);
    msg.saveChanges();
    msg.writeTo(System.out);
    msg.setSubject(subject);
    Transport.send(msg);
    </p>
    <B><U>See you can add above code in your program and see the magic</U></B>
    Bye
    regards--
    Ashish
    </html>

  • Need to send the text file using webservice

    Hi,
    I want to send the text file with contains data through oracle pl/sql using webservice. How can i handle this program?
    Kindly share with your details.
    Thanks in advance,
    Maran

    user8732035 wrote:
    I want to send the text file with contains data through oracle pl/sql using webservice. How can i handle this program?Web services supply XML structured data. Not text files.
    PL/SQL supports web services (XML output) and web procedures (text and binary output).
    You need to clarify your requirements.

Maybe you are looking for