How to specify the directory in which we want to store the uploaded files

Hello !!
I am using apache commonfile upload for uploading my files.I followed the user guide and tried to run a program,but my problem is I am not able to understand as to how to mention the directory in which the uploaded file will be saved..My code is given below :
package r;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;
import java.util.*;
import org.apache.commons.fileupload.*;
import org.apache.commons.fileupload.servlet.*;
import org.apache.commons.fileupload.disk.*;
import org.apache.commons.io.*;
import java.lang.Exception;
public class fileupload extends HttpServlet
     public void doGet(HttpServletRequest request,HttpServletResponse response)throws IOException,ServletException
               // Check that we have a file upload request
              boolean isMultipart = ServletFileUpload.isMultipartContent(request);
             System.out.println(isMultipart);
             if (ServletFileUpload.isMultipartContent(request))
             // Create a factory for disk-based file items
               FileItemFactory factory = new DiskFileItemFactory();
               // Create a new file upload handler
               ServletFileUpload upload = new ServletFileUpload(factory);
               // Parse the request
               try {
                           List items= upload.parseRequest(request);               
                         Iterator iter = items.iterator();
                         while (iter.hasNext())
                               FileItem item = (FileItem) iter.next();                    
                             if (item.isFormField()) //NORMAL FORM FIELD
                             String name = item.getFieldName();
                              String value = item.getString();
                              System.out.println(value);                                                             
                              else
                             String fileName = item.getName();
                             System.out.println(fileName);
                                String contentType = item.getContentType();
                              File saveTo = new File("/info/upload_files/myFile.jpeg");
                         try
                                   item.write(saveTo);
                                   System.out.println("File written" );                    
                         catch(Exception e)
                                     System.out.println("File not written");
                               // InputStream fs= item.getInputStream();                    
                               fileName = FilenameUtils.getName(fileName);
                                System.out.println(fileName);
                    }//end of try
          catch (Exception e) { }
     public void doPost(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException
             doGet(request,response);
The problem is that the control doesn't reach the try statement and I get " File not written" on the console because it enters catch everytime..Please tell me how the path to the directory should be given...Rest of the code is working fine

No, the problem is that when an Exception is thrown, you ignore it completely and throw away all the information associated with it. That leaves you to guess at what the problem is. So instead of answering your guess at a good question, I'm going to suggest that in all of your catch blocks you put this code:e.printStackTrace();Then you can look at the output in the log file and see what the problem is. Start from there.

Similar Messages

  • How to specify the database file path when create FDM application

    Dear All,
    How to specify the database file path (MSSQL) when create FDM application?
    Right now, all data file are placed in the D:\ . I want to specify the database files (log and mdf file) in other place. How to do it?
    Thanks.

    Where is the highS2.xml located on the disk? If you add it to your project you should set its Build Action to Content and its Copy To Output Directory to Always in Visual Studio:
    Please remember to close your threads by marking helpful posts as answer once your issue has been solved and then start a new thread if you have a new question.

  • Jaas How to specify the config file

    Hi
    I'm working on a web app based on Sun's App Server 8. I am implementing security using a Jaas LoginModule. I cant figure out how i can specify the config file because if i make the change in the java.security file the server throws all sorts of exceptions....... i'm not sure how i can go about that..
    Thanks..

    Read the documentation. There are several different files that you can use to specifiy the handler to use for a particular context. One is ${user.home}/.java.login.config

  • How to list the uploaded files  in jsp

    hello every body .
    I wanted to request to plese let me know the method as to how get the uploaded files on the server to a jsp page . i am able to upload the files but not able to get those files listed on the web page . please help me ...........

    i tried this also and it didn't wok instead my page got filled with these lines
    The file named CSAJSP-Chapter12.pdf is successfully uploaded [Ljava.lang.String;@1ab11b0 [Ljava.lang.String;@1ab11b0 [Ljava.lang.String;@1ab11b0 [Ljava.lang.String;@1ab11b0 [Ljava.lang.String;@1ab11b0 [Ljava.lang.String;@1ab11b0 [Ljava.lang.String;@1ab11b0 [Ljava.lang.String;@1ab11b0 [Ljava.lang.String;@1ab11b0 [Ljava.lang.String;@1ab11b0 [Ljava.lang.String;@1ab11b0 [Ljava.lang.String;@1ab11b0 [Ljava.lang.String;@1ab11b0 [Ljava.lang.String;@1ab11b0 [Ljava.lang.String;@1ab11b0 [Ljava.lang.String;@1ab11b0 [Ljava.lang.String;@1ab11b0 [Ljava.lang.String;@1ab11b0 [Ljava.lang.String;@1ab11b0 [Ljava.lang.String;@1ab11b0 [Ljava.lang.String;@1ab11b0 [Ljava.lang.String;@1ab11b0 [Ljava.lang.String;@1ab11b0 [Ljava.lang.String;@1ab11b0 [Ljava.lang.String;@1ab11b0 [Ljava.lang.String;@1ab11b0 [Ljava.lang.String;@1ab11b0 [Ljava.lang.String;@1ab11b0
    . I am not able to make out any thing . plese  suggest me  some solution                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • How to display the uploaded file

    Hi All ,
    I have the below requirement .
    1. Upload the file  (any file type)  -- no problem done with FileUpload UI element.
    2. Display the uploaded file as icon or link .
    3. User should be able to delete the uploaded file using  icon or link (depends upon step2 ).
    I am struggling with step2 and 3 .
    Please guide me
    Regards,
    Ravi

    Hi,
    You can use the file download UI element for your requirment. You will have the Resource type context that is used to bind the File upload UI element. bind the same context to the file download UI element. And hence without any extra coding your requirment is achieved.
    For deleting the Uploaded file delete the context element of type reource.
    For your reference refer to the following link
    http://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/202a850a-58e0-2910-eeb3-bfc3e081257f
    Regards,
    Raju Bonagiri

  • How to specify the download file name??

    Hi guys~~~
    I have servlet which can generate a *.pdf file,I found if I didn't setContentType="application/pdf",I can download it!!But the download file name is my servlet file name.If I want to change the download file name,How do I do????
    thanx a lot!!!Best regard!

    Thanx for ur help...But I encounter a new charllenge now...
    I use a javascript(window.open("/myservlet")) to open the download file servlet.
    Everything is okay.But when I finish downloading the file which window I opened cant close itself automatically.
    I am really not understand the header parameter of the HTML header,could someone give me something about this??
    Thanx again!!!!

  • How to Specify the Log File address as RootDir/Logs/Error.log in Log4j

    I have a web application,
    How to configure the log4j Rolling file Appender in that.
    I want to logs to be redirected to the RootDir/logs/Error.log.
    Currently, I m using following configuration:
    # This file must live on the classpath of the jvm
    # Set root logger level to DEBUG and log to both stdout and rollingFile appenders
    # (see below for their definitions)
    # The set of possible levels are: DEBUG, INFO, WARN, ERROR and FATAL
    log4j.rootLogger=INFO, stdout, R
    ####### Console appender ######
    log4j.appender.stdout=org.apache.log4j.ConsoleAppender
    log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
    # Pattern to output the caller's file name and line number.
    # The pattern: Date Priority (Filename:Line Number) - Message\n
    log4j.appender.stdout.layout.ConversionPattern=%d %-5p (%F:%L) - %m%n
    #### Second appender writes to a file
    log4j.appender.R=org.apache.log4j.RollingFileAppender
    log4j.appender.R.File=Error.log
    # Control the maximum log file size
    log4j.appender.R.MaxFileSize=100KB
    # Archive log files (one backup file here)
    log4j.appender.R.MaxBackupIndex=1
    log4j.appender.R.layout=org.apache.log4j.PatternLayout
    log4j.appender.R.layout.ConversionPattern=%d %-5p (%F:%L) - %m%n
    Thanks for your replies in advance.

    Please follow the following steps, will work.
    To enable log4j logging to a file on lunar pages do the following:
    1) Create a servlet class that will initialize log4j. Here is
    the code:
    package logging;
    import org.apache.log4j.PropertyConfigurator;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    public class Log4jInit extends HttpServlet {
    public
    void init() {
    String prefix = getServletContext().getRealPath("/");
    String file = getInitParameter("log4j-init-file");
    // if the log4j-init-file is not set, then no point in trying
    if(file != null) {
    PropertyConfigurator.configure(prefix+file);
    public
    void doGet(HttpServletRequest req, HttpServletResponse res) {
    2) In your web.xml file add the following entry:
    <servlet>
    <servlet-name>log4j-init</servlet-name>
    <servlet-class>logging.Log4jInit</servlet-class>
    <init-param>
    <param-name>log4j-init-file</param-name>
    <param-value>WEB-INF/classes/log4j.lcf</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
    </servlet>
    3) Create a log4j.lcf file located in your WEB-INF/classes directory
    as with the following entries:
    log4j.rootLogger=debug, R
    # yourdirectory below is where your site lives.
    log4j.appender.R=org.apache.log4j.RollingFileAppender
    log4j.appender.R.File=/home/yourdirectory/public_html/logs/out.log
    log4j.appender.R.MaxFileSize=500KB
    # Keep one backup file
    log4j.appender.R.MaxBackupIndex=1
    log4j.appender.R.layout=org.apache.log4j.PatternLayout
    log4j.appender.R.layout.ConversionPattern=%d %-5p [%c] %m%n
    4) Add logging to your class. Here is an example:
    import org.apache.log4j.Logger;
    public class Example {
    static Logger logger = Logger.getLogger(Example.class);
    public void doSomething() {
    logger.debug("testing logging");
    5) make sure you have the log4j-1.2.8.jar file located in your WEB-INF/lib directory.
    That should do it!

  • How to list the uploaded files on the server with a jsp page

    hi every body , iam stuck up with yhis problem . I a have use Random Access File to upload files to the web server , now i want the user can see the files he /she has uploaded or the the files uploaded by others . plese help me how to implement this .
    Message was edited by:
    joshiashutosh

    hi every body , iam stuck up with yhis problem . I a
    have use Random Access File to upload files to the
    web server ,Huh?
    now i want the user can see the files he
    /she has uploaded or the the files uploaded by others
    . plese help me how to implement this .So get the directory using the File class the files are in and list the files inside, showing the result to the user... how difficult would that be?

  • How to restrict the upload file size in me21n/me22n/me23n?

    Hi Guru's,
    I have a requirement to restrict the user from attaching a local file more than 20MB in Purchase Order.
    In standard SAP system, the user can attach a file of any size in PO. How to restrict the size of the file?
    I have no clue how to achieve this? Any kind of help would be great...
    Thanks in Advance...
    Regards,
    Satyam

    Hi Guru's,
    The file size is now restricted in function GUI_UPLOAD. But this function module is used at many places. I want to restrict it only for Tcode: ME22n and ME23n.
    I thought of restricting it by sy-tcode field but sy-tcode value  is not passed to this function module in the run time.
    Could anyone help me on this how to restrict it for the above mentioned tcodes??
    Regards,
    Satyam

  • How to get the upload file from a html form ?

    I have a <input type=file ...> control in my form, and the user use that
              control to submit a file
              to my web server. The porblem is the getParameter() function of
              HttpServletRequest only return the
              filename. Does anyone know how to get the file body ?
              Frances
              

    http://www.servlets.com/jsp/examples/ch04/index.html#ex04_17
              Frances Fan <[email protected]> wrote:
              > I have a <input type=file ...> control in my form, and the user use that
              > control to submit a file
              > to my web server. The porblem is the getParameter() function of
              > HttpServletRequest only return the
              > filename. Does anyone know how to get the file body ?
              > Frances
              Dimitri
              

  • To Delete the uploaded file in Application Server

    Hi Friends,
    I developed an BSP Application displaying the results from ITAB though Iterator, for which , each row there is feature to upload a particular file in the Application Server, where I stored the file  path into a database table field.  .When I delete the the row, I am successfully get rid of the entire row including the file path.
    My Question.
    1. How to delete the uploaded file of the Application Server ?
    Please mail me in this regard.
    Regards
    CSM Reddy

    Hi,
    you have the keyword and you have the documentation. What is your problem?
    Search in the forums with keyword "delete dataset", there are lots of threads about this.
    Example
    Deletion of dataset in applicaiton server
    deleting file from AL11 Tcode
    Best regards
    Renald

  • How to specify source directory in File sender adpate using (NFS)?

    Hello experts,
    I am doing File-PI-Proxy scenario.
    Input file is available on machine which is within the Network area and FTP is not available on that machine.
    For this reason I am using the NFS Transport Protocol.
    In ID File sender I have specified Source Directory:-
    IP Address\Directory
    I am geeting the Error in RWB as 'Configured source directory '
    IP Address\Directory' does not exist'.
    Please suggest how to specify the Source Directory path.
    Regards,
    Jagesh

    Hi,
    If you want to use NFS protocol, then the file needs to be within the a folder in the XI server and not outside it, In your case if you need to use the file in a different machine which is on a network then try to use the FTP protocol.
    Refer this blog:
    /people/shabarish.vijayakumar/blog/2006/08/01/along-came-a-file-adapter-mr-ftp-and-rest-of-the-gang which shows the details of how you can install a local FTP and use it
    Regards,
    Nithiyanandam
    Edited by: Nithiyanandam A.U. on Mar 18, 2009 10:43 AM

  • Numbers to CSV export script: how to specify the encoding?

    Hi,
    I'm using the following script to export a Numbers document to CSV:
    # Command-line tool to convert an iWork '09 Numbers
    # document to CSV.
    # Parameters:
    # - input: Numbers input file
    # - output: CSV output file
    # Attik System, Philippe Lang
    # Creation date: 31 mai 2012
    # Modification date:
    on run argv
      # We retreive the path of the script
              set myPath to (path to me)
              tell application "Finder" to set myFolder to folder of myPath
      # We get the command line parameters
              set input_file to item 1 of argv
              set output_file to item 2 of argv
      # We retreive the extension of the file
              set theInfo to (info for (input_file))
              set extname to name extension of (theInfo)
      # Paths
              set input_file_path to (myFolder as text) & input_file
              set output_file_path to (myFolder as text) & output_file
              if extname is equal to "numbers" then
        tell application "Numbers"
          open input_file_path
          save document 1 as "LSDocumentTypeCSV" in output_file_path
          close every window saving no
        end tell
              end if
    end run
    It works fine, except that I don't know how to specify the encoding of the text in the CSV file (Latin1, MacRoman, Unicode). This option is available in the export dialog of Numbers. Any hint on how to do that is welcome. (GUI Scripting?)
    Where can I find documentation on the iWork "vocabulary" available? Is there a definitive documentation somewhere? I tried to record an manual export in the script editor, without success. Script is more or less empty.
    Thanks!
    Philippe Lang

    A further note from Yvan. He's made some revisions to the script sent earlier.
    --{code}
    --[SCRIPT export to CSV with selected encoding]
    I added some features.
    (1) Defining the encoding thru the preferences file apply only if
    the application is not in use because the file is read only once in a session.
    A test urge you to quit Numbers if it is running.
    (2) info for is deprecated so it may be removed by Apple tomorrow.
    I no longer use it.
    (3) just for the fun, I added a piece of code allowing you to select the encoding on the fly.
    Thanks to the property chooseEncodingInScript, at this time the script use Unicode (UTF-8)
    (4) I'm wondering which tool is used to launch this script,
    I don't know the way to pass arguments when I run one.
    Yvan KOENIG (VALLAURIS, France)
    2012/06/13
    property chooseEncodingInScript : false
    true = the script will ask you to select the encoding
    false = the script use the embedded encoding
    on run argv
      set input_file to (item 1 of argv) as text
      set output_file to (item 2 of argv) as text
      set myPath to (path to me) as text
              tell application "System Events"
      set theProcesses to name of every application process
      set myFolder to path of container of (disk item myPath)
      set input_file_path to myFolder & input_file
      set output_file_path to myFolder & output_file
      set extname to name extension of (disk item input_file)
      end tell
              if extname is "numbers" then
                        if "Numbers" is in theProcesses then error "Please, quit “Numbers” before running this script !"
      if chooseEncodingInScript then
                                  set theList to {"Mac OS Roman", "Unicode (UTF-8)", "Windows Latin 1"}
                                  set maybe to choose from list theList with prompt "Choose the default encoding applying to export as CSV"
      if maybe is false then
      error number -128
      else if item 1 of maybe is item 1 of theList then
                                            30 -- Mac OS Roman
      else if item 1 of maybe is item 2 of theList then
                                            4 -- Unicode (UTF-8)
      else
                                            12 -- Windows Latin 1
      end if
      else
                                  4 -- Unicode (UTF-8)
      end if
                        do shell script "defaults write com.apple.iWork.Numbers CSVExportEncoding  -int " & result
      tell application "Numbers"
      open input_file_path
                                  save document 1 as "LSDocumentTypeCSV" in output_file_path
      close every window saving no
      end tell
      end if
    end run
    --{code}
    Regards,
    Barry

  • How to create the SWF file which was included surrogate pairs.

    I would like to make sure how to create the SWF file which are included surrogate pairs.
    The error of outside the scope of unicode occurred when I compiled(mxmlc) the as file which was set surrogate pairs to 'Unicoderange'.
    Ex, I set the '  '(UTF-16 is '20B9F') to 'Unicoderange'.
    However, I cannot add the surrogate pairs.
    The error of outside the scope of Unicode occurred when I compiled the AS file.
    The reason of error was that the Unicode(UTF-16) of surrogate pairs is invalid.
    Then, I read the following pages.
    These pages are written that unicode-range supported surrogate pairs.
    http://livedocs.adobe.com/flex/3/html/help.html?content=fonts_07.html
    http://www.w3.org/TR/1998/REC-CSS2-19980512/fonts.html#descdef-unicode -range
    So please let me know how to create the SWF file which are included surrogate pairs.
    Environment
    - Flex3.5a
    - TTC: meiryo(ver6.02), msgothic(ver2.50), mspgothic(ver2.50)
    Thanks,
    Takeshi Ishihara.

    I've been able to create project jar files in Eclipse by selecting Export from the File menu, then choose Java - Jar file - and provide the required information, name, destination folder etc. But when I do this, I do not export other jars on the build path this way nor do I expect to do this. I am only concerned with creating a jar file of my own work. A jar file does not "contain" other jar files. If the jar file contains the main method, and requires other jars for it's execution, then you may wish to include a reference to required jars on the class path entry of the Manifest file of the jar file you create. I'm not sure how to create a Manifest file in eclipse though..

  • How to specify the target name while deploying a code in OSB-- Plz Help

    Hi all,
    Am working in creating a cluster environment. For my testing i created a new managed server(OSB_Server) in 9001 port in the admin console itself and that server started running. The default managed server(Admin_Server) is in 7001 port. So when i deploy a code in 7001 sb console the WSDL gets exposed in 7001 because the default admin server port is 7001. While deploying a code in service bus admin console we are not specifying the target name. So how to specify the target name while deploying the code in service bus admin console. Plz help me.
    Regards
    Prabhu

    Hi Prabhu,
    There are three kind of server architecture possible for OSB -
    1. Single server - Everything gets deployed on Admin server itself
    2. Admin Server + Single Managed Server for OSB -- OSB configuration gets deployed on OSB managed server. OSB resources (proxy service, WSDL, Schema) will remain available on OSB managed server port only and NOT on admin server port
    3. Admin Server + OSB cluster -- OSB configuration gets deployed on OSB cluster. OSB resources (proxy service, WSDL, Schema) will remain available on OSB Cluster port(s) only and NOT on admin server port
    Converting one type of server architecture to any other type, requires a manual tedious process, so it is suggested that you create domain accordingly i.e. if you need clusters then while creating domain itself, create OSB cluster, so that all OSB applications gets deployed to OSB cluster. I will suggest you to create a clustered domain from scratch and import the configuration from your existing domian to this new clustered domain.
    You may refer-
    http://download.oracle.com/docs/cd/E17904_01/doc.1111/e15022/toc.htm
    Regards,
    Anuj

Maybe you are looking for

  • MacBook Pro dont wake up properly

    I have activated hot corner on my Macbook Pro 17" when I leave my desk for a short time I bring the mouse on hot corner and it goes to sleep. Some time when I move my mouse screen will be lightened and mouse will be visible but login screen wont come

  • Sega Genesis H5380BD only black and white.

    I just got this projector and trying to set it up with all my consoles and the like, but I can't get the Sega Genesis to give me any color on it through composite or S-Video. My NES, Famicom, SNES, and PC-Engine all give me color through composite. T

  • Udpating to IOS 7.0 has frosen my Ipdad 2

    I updated my ipad 2 with the new IOS 7.0.1 and now it wont reboot. I;ve tried resetting the ipad but that wont work. Help please.

  • Clicking the Time Machine icon does nothing.

    So I have backed up to an external hard-drive, and would like to confirm my backup. But clicking the Time Machine icon does nothing. Is anyone else experiencing this?

  • Wrong user ID appearing in entered by field of planned Maintenance Orders

    Hi, Only few planned orders those are generating from maintenance plan (Having order types PM02  and PM05 for QM Inspection plan), Instead of user ID system is being taken a code in entered by field as {IP1020100416 It looks like the combination of I