title: How to change the default folder for uploading file in jboss
body: <p>I am trying to upload a file, I am trying to change the default location of the uploaded file. How to change this please suggest ?</p>
  
  <pre><code>package Controller;
  
  import java.io.File;  
  import java.io.IOException;  
  import java.io.PrintWriter;  
  import java.util.Iterator;  
  import java.util.List;  
  
  import javax.servlet.RequestDispatcher;
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.Cookie;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import javax.servlet.http.HttpSession;
  
  import org.apache.commons.fileupload.FileItem;
  import org.apache.commons.fileupload.FileItemFactory;
  import org.apache.commons.fileupload.FileUploadException;
  import org.apache.commons.fileupload.disk.DiskFileItemFactory;
  import org.apache.commons.fileupload.servlet.ServletFileUpload;
  import org.apache.commons.io.FilenameUtils;
  
  import requests.Connect;
  import display.DisplayLog;
  /** * Servlet implementation class ControlServlet
   */
  public class ControlServlet extends HttpServlet{
  
      private static final long serialVersionUID = 1L;
      boolean result;
      private boolean isMultipart;
      private String filePath;
      private int maxFileSize = 1000 * 1024;
      private int maxMemSize = 1000 * 1024;
      private File file ;
  
      public ControlServlet() {
          super();
          // TODO Auto-generated constructor stub
      }
  
      /**     
       * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
       */
          protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  
  
          }
  
      /**
       * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
       */
      protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
      {
          HttpSession session=request.getSession();
          String userName = request.getParameter("username");
        isMultipart = ServletFileUpload.isMultipartContent(request);
          response.setContentType("audio/mpeg3;audio/x-mpeg-3;video/mpeg;video/x-mpeg;text/xml");
          PrintWriter out = response.getWriter( );
  
          if (isMultipart) {  
              // Create a factory for disk-based file items  
              FileItemFactory factory = new DiskFileItemFactory();  
              // Create a new file upload handler  
              ServletFileUpload upload = new ServletFileUpload(factory);  
             try {  
                // Parse the request  
                List items = upload.parseRequest(request);  
               Iterator iterator = items.iterator();  
               while (iterator.hasNext()) {  
                 FileItem item = (FileItem) iterator.next();  
                 if (!item.isFormField())  
                  {  
                   String fileName = item.getName();      
                   if (fileName != null) {
                       fileName = FilenameUtils.getName(fileName);
                   }
                   String root = getServletContext().getRealPath("/");  
                   root = "F/images";
                   File path = new File(root + "/uploads");
  
                   if (!path.exists())  
                    {  
                     boolean status = path.mkdirs();  
                   }  
                   File uploadedFile = new File(path + "/" + fileName);  
                   System.out.println(" Prashant File Upload Location is "); 
                 //  System.out.println(uploadedFile.getAbsolutePath());  
                   System.out.println("fileName is " +fileName);
                   System.out.println("root is " + root);
                   System.out.println("path is " + path);
                    if(fileName!="")  
                    {   
                        item.write(uploadedFile);  
                        System.out.println(" Prashant File Upload Location 2 is "); 
                        System.out.println(uploadedFile.getAbsolutePath());  
                        out.println("&lt;h1&gt;File Uploaded Successfully....:-)&lt;/h1&gt;");
                    }
                    else
                    {       
                       out.println(uploadedFile.getAbsolutePath());  
                        out.println("&lt;h1&gt;File Uploaded Successfully....:-)&lt;/h1&gt;");
                        System.out.println("file not found");  
                    }
  
                 }  
                  else  
                  {  
                    String abc = item.getString();  
                  }  
               }  
             } catch (FileUploadException e) {  
                   out.println(e);  
             } catch (Exception e) {  
                   out.println(e);  
             }  
           }  
            else  
            {  
              out.println("Not Multipart");  
            }          
          System.out.println("print this Prashant" + userName);
          session.setAttribute("username",userName);
          request.setAttribute("username","prashant");
      //  RequestDispatcher myDispatch = request.getRequestDispatcher("Index.jsp");
          //myDispatch.forward(request, response);
  }
  
  }
  </code></pre>
  
  <p>I am getting this as default folder F:\jboss-4.2.3.GA-jdk6\jboss-4.2.3.GA\bin\ please help i am new to this</p>