Servlet- How to send the file as argument

I am able to compile the below program. But when I open it in explorer I m not able to get the response. Its giving me the error. Actually the program requires the file from the user. I am giving that in the url in the folowing way
http://localhost:8080/examples/servlet/ListManagerServlet?aniketh
Where aniketh is the file which I m providing.
Please help me out with this.
import java.util.Vector;
import java.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class ListManagerServlet extends HttpServlet
private Vector addresses;
private String filename;
public void init(ServletConfig config) throws ServletException
super.init(config);
System.out.println("Before");
filename = config.getInitParameter("addressfile");
if(filename == null)
throw new UnavailableException(this,
"The \"addressfile\" property "+
"must be set to a file name");
try
     System.out.println("After");
ObjectInputStream in =
new ObjectInputStream(new FileInputStream(filename));
addresses = (Vector)in.readObject();
in.close();
catch(FileNotFoundException e) { addresses = new Vector(); }
catch(Exception e)
throw new UnavailableException(this,
"Error reading address file: "+e);
protected void doGet(HttpServletRequest req,
HttpServletResponse res)
throws ServletException, IOException
res.setContentType("text/html");
res.setHeader("pragma", "no-cache");
PrintWriter out = res.getWriter();
out.print("<HTML><HEAD><TITLE>List Manager</TITLE></HEAD>");
out.print("<BODY><H3>Members:</H3><UL>");
for(int i=0; i<addresses.size(); i++)
out.print("<LI>" + addresses.elementAt(i));
out.print("</UL><HR><FORM METHOD=POST>");
out.print("Enter your email address: <INPUT TYPE=TEXT NAME=email><BR>");
out.print("<INPUT TYPE=SUBMIT NAME=action VALUE=subscribe>");
out.print("<INPUT TYPE=SUBMIT NAME=action VALUE=unsubscribe>");
out.print("</FORM></BODY></HTML>");
out.close();
protected void doPost(HttpServletRequest req,
HttpServletResponse res)
throws ServletException, IOException
String email = req.getParameter("email");
String msg;
if(email == null)
res.sendError(res.SC_BAD_REQUEST,
"No email address specified.");
return;
if(req.getParameter("action").equals("subscribe"))
if(subscribe(email))
msg = "Address " + email + " has been subscribed.";
else
res.sendError(res.SC_BAD_REQUEST,
"Address " + email + " was already subscribed.");
return;
else
if(unsubscribe(email))
msg = "Address " + email + " has been removed.";
else
res.sendError(res.SC_BAD_REQUEST,
"Address " + email + " was not subscribed.");
return;
res.setContentType("text/html");
res.setHeader("pragma", "no-cache");
PrintWriter out = res.getWriter();
out.print("<HTML><HEAD><TITLE>List Manager</TITLE></HEAD><BODY>");
out.print(msg);
out.print("<HR><A HREF=\"");
out.print(req.getRequestURI());
out.print("\">Show the list</A></BODY></HTML>");
out.close();
public String getServletInfo()
return "ListManagerServlet 1.0 by Stefan Zeiger";
private synchronized boolean subscribe(String email) throws IOException
if(addresses.contains(email)) return false;
addresses.addElement(email);
save();
return true;
private synchronized boolean unsubscribe(String email) throws IOException
if(!addresses.removeElement(email)) return false;
save();
return true;
private void save() throws IOException
ObjectOutputStream out =
new ObjectOutputStream(new FileOutputStream(filename));
out.writeObject(addresses);
out.close();
}

i dont need file from the user. Actually the file -aniketh is the one which contains all the email address who are registered on particular site(for example). So if any user is coming and trying to register then it will check in the the file aniketh and see if the user is existing or not. If yes then it will pop up user exist and if no then it will create a subscribe the user. I hope you got wht i am saying. Now I want that my servlet should use that file. SO my question is how to make my servlet use that file. DO i have to passs it in address bar or something else......
Plz reply
appreciate in advance
Message was edited by:
aniketh_parmar

Similar Messages

  • How to send the file contents in the application server to ftp server

    Hi,
    how to send the file contents in the application server to ftp server.
    regards,
    sree

    Test SAP FTP functions
    DATA: BEGIN OF MTAB_DATA OCCURS 0,
    LINE(132) TYPE C,
    END OF MTAB_DATA.
    DATA: MC_PASSWORD(20) TYPE C,
    MI_KEY TYPE I VALUE 26101957,
    MI_PWD_LEN TYPE I,
    MI_HANDLE TYPE I.
    START-OF-SELECTION.
    MC_PASSWORD = 'password'.
    DESCRIBE FIELD MC_PASSWORD LENGTH MI_PWD_LEN.
    *-- FTP_CONNECT requires an encrypted password to work
    CALL 'AB_RFC_X_SCRAMBLE_STRING'
         ID 'SOURCE' FIELD MC_PASSWORD ID 'KEY' FIELD MI_KEY
         ID 'SCR' FIELD 'X' ID 'DESTINATION' FIELD MC_PASSWORD
         ID 'DSTLEN' FIELD MI_PWD_LEN.
    CALL FUNCTION 'FTP_CONNECT'
         EXPORTING
           USER            = 'userid'
           PASSWORD        = MC_PASSWORD
           HOST            = 'servername'
           RFC_DESTINATION = 'SAPFTP'
         IMPORTING
           HANDLE          = MI_HANDLE
         EXCEPTIONS
           NOT_CONNECTED   = 1
           OTHERS          = 2.
    CHECK SY-SUBRC = 0.
    CALL FUNCTION 'FTP_COMMAND'
         EXPORTING
           HANDLE = MI_HANDLE
           COMMAND = 'dir'
         TABLES
           DATA = MTAB_DATA
         EXCEPTIONS
           TCPIP_ERROR = 1
           COMMAND_ERROR = 2
           DATA_ERROR = 3
           OTHERS = 4.
    IF SY-SUBRC = 0.
      LOOP AT MTAB_DATA.
        WRITE: / MTAB_DATA.
      ENDLOOP.
    ELSE.
    do some error checking.
    ENDIF.
    CALL FUNCTION 'FTP_DISCONNECT'
         EXPORTING
           HANDLE = MI_HANDLE
         EXCEPTIONS
           OTHERS = 1.
    Execute external commands (FTP Scripts)
    The following code shows the syntax of the FM 'SXPG_COMMAND_EXECUTE'. You pass it the external command created within transaction SM69 and it will execute it.
    DATA: ld_comline 
    LIKE sxpgcolist-name,
            ld_param    LIKE sxpgcolist-parameters,
            ld_status   LIKE extcmdexex-status,
            ld_output   LIKE btcxpm OCCURS 0 WITH HEADER LINE,
            ld_subrc    LIKE sy-subrc.
      REFRESH ld_output.
      MOVE 'FTP_DATA_IN' to ld_comline.         "Maintained using trans SM69
    Execute external command, contained in 'ld_comline'
      CALL FUNCTION 'SXPG_COMMAND_EXECUTE'
           EXPORTING
                commandname                   = ld_comline
              additional_parameters   = ld_param  "Params passed to script
              operatingsystem              
    = 'UNIX'
           IMPORTING
                status                        = ld_status
           TABLES
                exec_protocol                 = ld_output
           EXCEPTIONS
                no_permission
                     = 1
                command_not_found
                 = 2
                parameters_too_long          
    = 3
                security_risk                
    = 4
                wrong_check_call_interface    = 5
                program_start_error           = 6
                program_termination_error     = 7
                x_error                       = 8
                parameter_expected            = 9
                too_many_parameters           = 10
                illegal_command               = 11
                wrong_asynchronous_parameters = 12
                cant_enq_tbtco_entry
              = 13
                jobcount_generation_error
         = 14
                OTHERS                       
    = 15.
      IF sy-subrc NE 0.
      ENDIF.

  • How to send the file in *application server* as an email?

    Hi,
    I have a file in application server and I want to send that file as an email from application server.
    Please let me know how to do it.

    Hi Suman,
    look here:
    Re: How to send an email from Application server?
    Regards, Dieter

  • Jms queues how to send the files?

    can we send files(txt,pdf,xml) to jms queues? here jms is sender?

    Hi,
    please go through the below link.
    http://scn.sap.com/docs/DOC-54030
    http://www.stechno.net/sap-notes.html?view=sapnote&id=856346
    Regards
    srinivas

  • How to send the Event Listener arguments in AS3?

    In MXML
    <mx:Button click="clickHandler();"
    mouseDown="downHandler(event);" mouseOver="overHandler(btn);"
    mouseMove="moveHandler('RAJAN');"/>
    but AS3
    var btn:Button = new Button();
    btn.addEventListener(MouseEvent.CLICK, clickHandler, flase,
    0, true);
    only this kind of AS3 event only added, any other possibility
    to pass the arguments to handler function.
    please help.

    From that link:
    If you define an event listener inline (inside the MXML tag),
    you can add any number of parameters as long as the listener
    function's signature agrees with that number of parameters.
    If you add a listener with the addEventListener() method (in
    ActionScript), you cannot pass any additional parameters to the
    listener function, and that listener function can declare only a
    single argument, the Event object (or one of its subclasses).
    To pass additional parameters to listener functions defined
    in AS, you must define the parameters in the listener function and
    then call some other method passing it the additional parameters in
    the call from the listener.
    You can also define your own custom events, and then you are
    free to define what args your event listeners take, and access the
    data from the event object.

  • How to send a file from FTP to external server

    My requirement is to send a file from FTP to D3(External) server.
    Now I am able to store the file in Appln server.
    I want to send the file created by the program thru FTP to D3 server.
    I know the username,Password,HostID,RFC destination details.
    How to send the file from FTP to D3.
    If u have any program,Plz send it...
    I dont want the function modules name...I want the example code ....
    Thanks in advance.

    Hi Sumi,
    You could do it so that you create a .bat or .cmd script to your server which does your ftp transfer.
    To do this you must use sm69 to create a external operating system command which you can call from FM SXPG_COMMAND_EXECUTE. To SXPG_COMMAND_EXECUTE you the file you need to transfer as a parameter.
    What happens is that your abap program passes the file to windows batch script (.bat .cmd) which will then do the transfer for you.
    Here's a sample of ftp-script for windows:
    echo open IP_ADDRESS_TO_YOUR_SERVER > c:zftp_transfer.ftp
    echo USERNAME>> c:zftp_transfer.ftp
    echo PASSWORD>> c:zftp_transfer.ftp
    echo put YOUR_FILE>> c:zftp_transfer.ftp
    echo quit>> c:zftp_transfer.ftp
    ftp -s:c:zftp_transfer.ftp
    also take a look here for more details:
    http://support.microsoft.com/?kbid=96269
    Ok, this might be a bit trivial but if your server is unix/aix etc.. Instead of using batch script you must do a shell script.
    Regards,
    Ville

  • How to send the report output to the application server in a excel file

    Hello,
    how to send the report output to the application server in a excel file.
    and the report runs in background.
    Thanks in advance.
    Sundeep

    Dear Sundeep.
    I'm providing you with the following piece of code ... Its working fine for me ... hopefully it suits your requirement ...
    D A T A D E C L A R A T I O N *
    TYPES: BEGIN OF TY_EXCEL,
    CELL_01(80) TYPE C,
    CELL_02(80) TYPE C,
    CELL_03(80) TYPE C,
    CELL_04(80) TYPE C,
    CELL_05(80) TYPE C,
    CELL_06(80) TYPE C,
    CELL_07(80) TYPE C,
    CELL_08(80) TYPE C,
    CELL_09(80) TYPE C,
    CELL_10(80) TYPE C,
    END OF TY_EXCEL.
    DATA: IT_EXCEL TYPE STANDARD TABLE OF TY_EXCEL,
    WA_EXCEL TYPE TY_EXCEL..
    E V E N T : S T A R T - O F - S E L E C T I O N *
    START-OF-SELECTION.
    Here you populate the Internal Table.
    Display - Top of the Page.
    PERFORM DISPLAY_TOP_OF_PAGE.
    E V E N T : E N D - O F - S E L E C T I O N *
    END-OF-SELECTION.
    SET PF-STATUS 'GUI_STATUS'.
    E V E N T : A T U S E R - C O M M AN D *
    AT USER-COMMAND.
    CASE SY-UCOMM.
    WHEN 'EXPORT'.
    Exporting the report data to Excel.
    PERFORM EXPORT_TO_EXCEL.
    ENDCASE.
    *& Form DISPLAY_TOP_OF_PAGE
    text
    --> p1 text
    <-- p2 text
    FORM DISPLAY_TOP_OF_PAGE .
    SKIP.
    WRITE: /05(128) SY-ULINE,
    /05 SY-VLINE,
    06(127) 'O R I C A'
    CENTERED COLOR 1,
    132 SY-VLINE.
    WRITE: /05(128) SY-ULINE,
    /05 SY-VLINE,
    06(127) 'Shift Asset Depreciation - Period/Year-wise Report.'
    CENTERED COLOR 4 INTENSIFIED OFF,
    132 SY-VLINE.
    WRITE: /05(128) SY-ULINE.
    E X C E L O P E R A T I O N
    CLEAR: IT_EXCEL[],
    WA_EXCEL.
    PERFORM APPEND_BLANK_LINE USING 1.
    WA_EXCEL-cell_02 = ' XYZ Ltd. '.
    APPEND WA_EXCEL TO IT_EXCEL.
    CLEAR: WA_EXCEL.
    WA_EXCEL-cell_02 = 'Shift Asset Depreciation - Period/Year-wise Report.'.
    APPEND WA_EXCEL TO IT_EXCEL.
    PERFORM APPEND_BLANK_LINE USING 1.
    ENDFORM. " DISPLAY_TOP_OF_PAGE
    *& Form APPEND_BLANK_LINE
    text
    -->P_1 text
    FORM APPEND_BLANK_LINE USING P_LINE TYPE I.
    DO P_LINE TIMES.
    CLEAR: WA_EXCEL.
    APPEND WA_EXCEL TO IT_EXCEL.
    enddo.
    ENDFORM.
    *& Form EXPORT_TO_EXCEL
    text
    --> p1 text
    <-- p2 text
    FORM EXPORT_TO_EXCEL .
    DATA: L_FILE_NAME(60) TYPE C.
    Create a file name
    CONCATENATE 'C:\' 'Shift_Depn_' SY-DATUM6(2) '.' SY-DATUM4(2)
    '.' SY-DATUM+0(4) INTO L_FILE_NAME.
    Pass the internal table (it_excel which is already populated )
    to the function module for excel download.
    CALL FUNCTION 'WS_EXCEL'
    exporting
    filename = L_FILE_NAME
    tables
    data = IT_EXCEL
    exceptions
    unknown_error = 1
    others = 2.
    if sy-subrc <> 0.
    message e001(ymm) with 'Error in exporting to Excel.'.
    endif.
    ENDFORM. " EXPORT_TO_EXCEL
    *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    When you click the button - Export to Excel ( GUI-Status) you'll be able to export the content of the Internal Table to an Excel file .......
    Regards,
    Abir
    Don't forget to award Points *

  • How do I scan a photo to a file and then send the file as an attachment via email.

    How do I scan a photo to a file and then send the file as an attachment  via email.

    All of this depends largely on what printer /software you have, which Email client you use and to some extent which OS you are running.
    Most HP printers have HP Solution Center which is used to set up scanning,choosing where to save,etc. Once a file/photo is scanned and saved to the folder, open the folder.Select the file and at the top of the window should be the option to 'Email'.
    ******Clicking the Thumbs-Up button is a way to say -Thanks!.******
    **Click Accept as Solution on a Reply that solves your issue to help others**

  • How to send the PDF file to FAX will the nast table updates

    Hi all,
    How to send the PDF file to FAX. Will the nast table updates ( which fields updates ).
    Need is once fax is send for that delivery, again it should not fax again. Will the nast table helps to check the sent fax.
    Please give me sutable suggessions....

    Have you checked Forums » Community Discussions » Code Snippets 
    I believe there were some examples on converting/sending PDF.
    Or check FM 'SO_DOCUMENT_SEND_API1' and documentation for it.

  • How to send the pdf file....

    How to send the pdf file which is an outpu of smart form to sap users.
    How to delete the pdf file as soon as it was sent.

    Have you checked Forums » Community Discussions » Code Snippets 
    I believe there were some examples on converting/sending PDF.
    Or check FM 'SO_DOCUMENT_SEND_API1' and documentation for it.

  • I have to send large files like 5MB or biger via mobile phone, but in that cases phone is telling mi to plug in power. And when I do that, there is no problem to send the file. For smaller files there is no problem. How can I solve the problem? Because wh

    I have to send large files like 5MB or biger via mobile phone, but in that cases phone is telling mi to plug in power. And when I do that, there is no problem to send the file. For smaller files there is no problem. How can I solve the problem? Because when I'm not at home I can't plug in the power.

    hi,
    I am sending file from server to client i.e client will request for a file and service will send it back....... no socket connection is there...I am using JBOSS and apache axis.
    pls help me out.....
    Rashi

  • HT2500 how can i insert a file in a mail message i send to someone?  i don't want the picture to be open or the text to be displayed.  I want to send the file as a file.  Pleas advise.

    how can i insert a file in a mail message i send to someone?  i don't want the picture to be open or the text to be displayed.  I want to send the file as a file.  Pleas advise.  thank you.

    Attach it to the message. An attachment is an attachment -- if it is displayed or not by the recipient's e-mail client is not under your control.
    You can zip it (compress it) before sending it; if it's text, you should zip it anyway; if it's JPEG, zipping will not reduce the size (in fact, it's even possible it may increase it slightly), but most e-mail clients do not display what's inside a zip archive.

  • I want to copy and paste files i recieved on my gmail to my flash drive.How do i send the files to my flsh drive?

    I dont have a copy machine,someone send me a Letter Head to my email adress.
    I want to send the files to my flash drive,how do i do that?

    Why are you still using that 4 tear old version of Firefox?
    Firefox 2.0.0.2 was released on 2007-02-19.

  • Please help!!!!!! i filled out a job application using adobe reader but i cannot send the file back via email because the file is protected with a lock. how do i unlock this file to send it?!!!!!!!!!

    please help!!!!!! i filled out a job application using adobe reader but i cannot send the file back via email because the file is protected with a lock. how do i unlock this file to send it?!!!!!!!!!

    Hi kevinv1987,
    It doesn't sound like the PDF was password protected (or Adobe Reader would prompt you for a password). Instead, it sounds like that file may be marked locked by your operating system. Are you on Mac OS or Windows? In either case, here are instructions for removing the lock icon from the file:
    Remove the Lock Icon from a Folder in Windows 7 (check Microsoft's website if you have a different version of Windows)
    On Mac OS, select the file in the Finder, and choose File > Get Info. Then, just deselect the Lock checkbox.
    Please let us know how it goes.
    Best,
    Sara

  • How to configure the file adaptor so as to send an sample XML message.

    Hi all ,
    I had done the configuration and now i want to test the scenario but i dont now how to do that ?.
    how to configure the file adaptor so as to send an sample XML message to the integration server ?.
    I am totally new to XI.
    please help me out how to do it.
    its an urgent.
    Thanks,
    shuja

    Hi,
    I think you should post your question Process Integration (PI) & SOA Middleware.
    Regards
    Message was edited by:
            Shehryar Khan

Maybe you are looking for

  • DTrace not working on a Virtual Machine

    Hi, I am using a virtual machine (created using VMware ESX server) which is installed on top of a physical Windows box. The VM is loaded with Solaris 10 x86 operating system. I added the java property in my application config file: java.extended.prop

  • How do i edit a flashdrive usb power point presentation with a pptx file

    My son has brought home a flashdrive USB from school (where they use Macs) with a power point presentation that needs to be edited but I can only open it up as a read only file. It has the suffix of .pptx. Does anyone have any suggestions to gain acc

  • Migrating from crystal report 8.5 to 10.0 giving error

    migrating from crystal report 8.5 to 10.0 giving error I am working in migrating my cr application to 10th ver from the existing 8.5 where we have to explicitly make a query in query builder and then attach it. I was using dsn in ms odbc for oracle d

  • ChaRM Copy Control for Ibase component

    Hi Team, I have created ZDCR which is copy of SDCR. And i have created ZDHF which is copy of SDHF. I have created the ZDHF as a subsequent document from ZDCR. While ZDHF is created, the Ibase component is not getting copied from ZDCR. How to copy the

  • Add-in not working in Word

    I am running Office 365 in Windows 7 Pro and have just upgraded Acrobat 9 Pro to Acrobat 11 Pro.  The add-in works fine in Excel and Powerpoint but not in Word.  I can do a "Save As" and produce a pdf but it's really annoying not to have the ribbon t