{"id":15958,"date":"2013-08-06T10:00:23","date_gmt":"2013-08-06T07:00:23","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/?p=15958"},"modified":"2014-02-23T23:28:18","modified_gmt":"2014-02-23T21:28:18","slug":"file-upload-example-in-servlet-and-jsp","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2013\/08\/file-upload-example-in-servlet-and-jsp.html","title":{"rendered":"File Upload Example in Servlet and JSP"},"content":{"rendered":"<p>Uploading File to server using Servlet and JSP is a common task in Java web application. Before coding your Servlet or JSP to handle file upload request, you need to know little bit about File upload support in HTML and HTTP protocol. If you want your user to choose files from file system and upload to server than you need to use &lt;input type=&#8221;file&#8221;\/&gt;. This will enable to choose any file form file system and upload to server. Next thing is that form method should be <a href=\"http:\/\/javarevisited.blogspot.sg\/2012\/03\/get-post-method-in-http-and-https.html\">HTTP POST<\/a> with enctype as <b>multipart\/form-data<\/b>, which makes file data available in parts inside request body. Now in order to read those file parts and create a File inside Servlet can be done by using ServletOutputStream. It&#8217;s better to use <b>Apache commons FileUpload<\/b>, an open source library. Apache FileUpload handles all low details of parsing HTTP request which confirm to RFC 1867 or <i>&#8220;Form based File upload in HTML\u201d<\/i>, when you set form method post and content type as &#8220;multipart\/form-data&#8221;.<\/p>\n<p><a name=\"more\"><\/a><\/p>\n<h2>Important points:<\/h2>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/07\/JavaSparrow-med3.jpg\"><img decoding=\"async\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/07\/JavaSparrow-med3-150x150.jpg\" alt=\"JavaSparrow-med\" width=\"150\" height=\"150\" class=\"alignright size-thumbnail wp-image-16096\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/07\/JavaSparrow-med3-150x150.jpg 150w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/07\/JavaSparrow-med3-200x200.jpg 200w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/07\/JavaSparrow-med3-100x100.jpg 100w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/07\/JavaSparrow-med3-42x42.jpg 42w\" sizes=\"(max-width: 150px) 100vw, 150px\" \/><\/a><\/p>\n<ol>\n<li>DiskFileItemFactory is default <a href=\"http:\/\/javarevisited.blogspot.co.uk\/2013\/01\/difference-between-factory-and-abstract-factory-design-pattern-java.html\">Factory class<\/a> for FileItem. When Apache commons read multipart content and generates FileItem, this implementation keep file content either in memory or in disk as temporary file, depending upon threshold size. By default DiskFileItemFactory has threshold size of 10KB and generates temporary files in temp directory, returned by System.getProperty(&#8220;java.io.tmpdir&#8221;). Both of these values are configurable and it&#8217;s best to configure these for production usage. You may get permission issues if user account used for running Server doesn&#8217;t have sufficient permission to write files into temp directory.<\/li>\n<li>Choose threshold size carefully based upon memory usage, keeping large content in memory may result in <a href=\"http:\/\/javarevisited.blogspot.sg\/2011\/09\/javalangoutofmemoryerror-permgen-space.html\">java.lang.OutOfMemory<\/a>, while having too small values may result in lot&#8217;s of temporary files.<\/li>\n<li>Apache commons file upload also provides FileCleaningTracker to delete temporary files created by DiskFileItemFactory. FileCleaningTracker deletes temporary files as soon as corresponding <a href=\"http:\/\/javarevisited.blogspot.sg\/2011\/12\/read-and-write-text-file-java.html\">File instance <\/a>is garbage collected. It accomplish this by a cleaner thread which is created when FileCleaner is loaded. If you use this feature, than remember to terminate this Thread when your web application ends.<\/li>\n<li>Keep configurable details e.g. upload directory, maximum file size, threshold size etc in config files and use reasonable default values in case they are not configured.<\/li>\n<li>It&#8217;s good to validate size, type and other details of Files based upon your project requirement e.g. you may wants to allow\u00a0 upload only images of certain size and certain types e.g. JPEG, PNG etc.<\/li>\n<\/ol>\n<h2>File Upload Example in Java Servlet and JSP<\/h2>\n<p>Here is the complete code for uploading files in Java web application using Servlet and JSP. This File Upload Example needs four files :<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<ol>\n<li>index.jsp which contains HTML content to setup a form, which allows user to select and upload file to server.<\/li>\n<li>FileUploader Servlet which handles file upload request and uses Apache FileUpload library to parse multipart form data<\/li>\n<li> web.xml to configure servlet and JSP in Java web application.<\/li>\n<li>result.jsp for showing result of file upload operation.<\/li>\n<\/ol>\n<h4>FileUploadHandler.java<\/h4>\n<pre class=\"brush:java\"> import java.io.File;\r\nimport java.io.IOException;\r\nimport java.util.List;\r\nimport javax.servlet.ServletException;\r\nimport javax.servlet.http.HttpServlet;\r\nimport javax.servlet.http.HttpServletRequest;\r\nimport javax.servlet.http.HttpServletResponse;\r\nimport org.apache.commons.fileupload.FileItem;\r\nimport org.apache.commons.fileupload.disk.DiskFileItemFactory;\r\nimport org.apache.commons.fileupload.servlet.ServletFileUpload;\r\n\r\n\/**\r\n * Servlet to handle File upload request from Client\r\n * @author Javin Paul\r\n *\/\r\npublic class FileUploadHandler extends HttpServlet {\r\n    private final String UPLOAD_DIRECTORY = \"C:\/uploads\";\r\n  \r\n    @Override\r\n    protected void doPost(HttpServletRequest request, HttpServletResponse response)\r\n            throws ServletException, IOException {\r\n      \r\n        \/\/process only if its multipart content\r\n        if(ServletFileUpload.isMultipartContent(request)){\r\n            try {\r\n                List&lt;FileItem&gt; multiparts = new ServletFileUpload(\r\n                                         new DiskFileItemFactory()).parseRequest(request);\r\n              \r\n                for(FileItem item : multiparts){\r\n                    if(!item.isFormField()){\r\n                        String name = new File(item.getName()).getName();\r\n                        item.write( new File(UPLOAD_DIRECTORY + File.separator + name));\r\n                    }\r\n                }\r\n           \r\n               \/\/File uploaded successfully\r\n               request.setAttribute(\"message\", \"File Uploaded Successfully\");\r\n            } catch (Exception ex) {\r\n               request.setAttribute(\"message\", \"File Upload Failed due to \" + ex);\r\n            }          \r\n         \r\n        }else{\r\n            request.setAttribute(\"message\",\r\n                                 \"Sorry this Servlet only handles file upload request\");\r\n        }\r\n    \r\n        request.getRequestDispatcher(\"\/result.jsp\").forward(request, response);\r\n     \r\n    }\r\n  \r\n}\r\n<\/pre>\n<h4>index.jsp<\/h4>\n<pre class=\"brush:xml\"> &lt;%@page contentType=\"text\/html\" pageEncoding=\"UTF-8\"%&gt;\r\n&lt;!DOCTYPE HTML PUBLIC \"-\/\/W3C\/\/DTD HTML 4.01 Transitional\/\/EN\"\r\n    \"http:\/\/www.w3.org\/TR\/html4\/loose.dtd\"&gt;\r\n&lt;html&gt;\r\n    &lt;head&gt;\r\n        &lt;meta http-equiv=\"Content-Type\" content=\"text\/html; charset=UTF-8\"&gt;\r\n        &lt;title&gt;File Upload Example in JSP and Servlet - Java web application&lt;\/title&gt;\r\n    &lt;\/head&gt;\r\n \r\n    &lt;body&gt; \r\n        &lt;div&gt;\r\n            &lt;h3&gt; Choose File to Upload in Server &lt;\/h3&gt;\r\n            &lt;form action=\"upload\" method=\"post\" enctype=\"multipart\/form-data\"&gt;\r\n                &lt;input type=\"file\" name=\"file\" \/&gt;\r\n                &lt;input type=\"submit\" value=\"upload\" \/&gt;\r\n            &lt;\/form&gt;          \r\n        &lt;\/div&gt;\r\n      \r\n    &lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<h4>result.jsp<\/h4>\n<pre class=\"brush:xml\"> &lt;%@page contentType=\"text\/html\" pageEncoding=\"UTF-8\"%&gt;\r\n&lt;!DOCTYPE HTML PUBLIC \"-\/\/W3C\/\/DTD HTML 4.01 Transitional\/\/EN\"\r\n    \"http:\/\/www.w3.org\/TR\/html4\/loose.dtd\"&gt;\r\n&lt;html&gt;\r\n    &lt;head&gt;\r\n        &lt;meta http-equiv=\"Content-Type\" content=\"text\/html; charset=UTF-8\"&gt;\r\n        &lt;title&gt;File Upload Example in JSP and Servlet - Java web application&lt;\/title&gt;\r\n    &lt;\/head&gt;\r\n \r\n    &lt;body&gt; \r\n        &lt;div id=\"result\"&gt;\r\n            &lt;h3&gt;${requestScope[\"message\"]}&lt;\/h3&gt;\r\n        &lt;\/div&gt;\r\n      \r\n    &lt;\/body&gt;\r\n&lt;\/html&gt;\r\n\r\n<\/pre>\n<h4>web.xml<\/h4>\n<pre class=\"brush:xml\">\r\n&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\r\n&lt;web-app version=\"2.5\" xmlns=\"http:\/\/java.sun.com\/xml\/ns\/javaee\" xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xsi:schemaLocation=\"http:\/\/java.sun.com\/xml\/ns\/javaee http:\/\/java.sun.com\/xml\/ns\/javaee\/web-app_2_5.xsd\"&gt;\r\n\r\n   &lt;servlet&gt;\r\n        &lt;servlet-name&gt;FileUploadHandler&lt;\/servlet-name&gt;\r\n        &lt;servlet-class&gt;FileUploadHandler&lt;\/servlet-class&gt;\r\n    &lt;\/servlet&gt;\r\n    &lt;servlet-mapping&gt;\r\n        &lt;servlet-name&gt;FileUploadHandler&lt;\/servlet-name&gt;\r\n        &lt;url-pattern&gt;\/upload&lt;\/url-pattern&gt;\r\n    &lt;\/servlet-mapping&gt;\r\n  \r\n  \r\n    &lt;session-config&gt;\r\n        &lt;session-timeout&gt;\r\n            30\r\n        &lt;\/session-timeout&gt;\r\n    &lt;\/session-config&gt;\r\n\r\n    &lt;welcome-file-list&gt;\r\n        &lt;welcome-file&gt;index.jsp&lt;\/welcome-file&gt;\r\n    &lt;\/welcome-file-list&gt;\r\n\r\n&lt;\/web-app&gt;\r\n<\/pre>\n<p>In summary just keep three things in mind while uploading files using Java web application<\/p>\n<ol>\n<li>Use HTML form input type as File to browse files to upload<\/li>\n<li>Use form method as post and enctype as multipart\/form-data<\/li>\n<li>Use Apache commons FileUpload in <a href=\"http:\/\/javarevisited.blogspot.sg\/2012\/01\/difference-between-page-include-and.html\">Servlet<\/a> to handle HTTP request with multipart data.<\/li>\n<\/ol>\n<h2>Dependency<\/h2>\n<p>In order to compile and run this Java web application in any web server e.g. <a href=\"http:\/\/javarevisited.blogspot.sg\/2013\/07\/how-to-configure-https-ssl-in-tomcat-6-7-web-server-java.html\">Tomcat<\/a>, you need to include following dependency JAR in WEB-INF lib folder.<\/p>\n<p>commons-fileupload-1.2.2.jar<\/p>\n<p>commons-io-2.4.jar<\/p>\n<p>If you are using Maven than you can also use following dependencies :<\/p>\n<pre class=\"brush:xml\"> &lt;dependency&gt;\r\n     &lt;groupId&gt;commons-fileupload&lt;\/groupId&gt;\r\n     &lt;artifactId&gt;commons-fileupload&lt;\/artifactId&gt;\r\n     &lt;version&gt;1.2.2&lt;\/version&gt;\r\n&lt;\/dependency&gt;\r\n&lt;dependency&gt;\r\n     &lt;groupId&gt;commons-io&lt;\/groupId&gt;\r\n     &lt;artifactId&gt;commons-io&lt;\/artifactId&gt;\r\n     &lt;version&gt;2.4&lt;\/version&gt;\r\n&lt;\/dependency&gt;\r\n<\/pre>\n<p>That&#8217;s all on <b>How to upload Files using Servlet and JSP in Java web application<\/b>. This File Upload example can be written using JSP, Filter or Servlet because all three are request\u2019s entry point in Java web application. I have used Servlet for handling File upload request for simplicity. By the way from Servlet 3.0 API, Servlet is supporting multipart form data and you can use getPart() method of HttpServletRequest to handle file upload.<br \/>\n&nbsp;<\/p>\n<div style=\"border: 1px solid #D8D8D8; background: #FAFAFA; width: 100%; padding-left: 5px;\"><b><i>Reference: <\/i><\/b><a href=\"http:\/\/javarevisited.blogspot.com\/2013\/07\/ile-upload-example-in-servlet-and-jsp-java-web-tutorial-example.html\">File Upload Example in Servlet and JSP &#8211; Java Web Application Tutorial Example<\/a> from our <a href=\"http:\/\/www.javacodegeeks.com\/jcg\">JCG partner<\/a> Javin Paul at the <a href=\"http:\/\/javarevisited.blogspot.com\/\">Javarevisited<\/a> blog.<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Uploading File to server using Servlet and JSP is a common task in Java web application. Before coding your Servlet or JSP to handle file upload request, you need to know little bit about File upload support in HTML and HTTP protocol. If you want your user to choose files from file system and upload &hellip;<\/p>\n","protected":false},"author":251,"featured_media":112,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[198],"class_list":["post-15958","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-jsp"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>File Upload Example in Servlet and JSP<\/title>\n<meta name=\"description\" content=\"Uploading File to server using Servlet and JSP is a common task in Java web application. Before coding your Servlet or JSP to handle file upload request,\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2013\/08\/file-upload-example-in-servlet-and-jsp.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"File Upload Example in Servlet and JSP\" \/>\n<meta property=\"og:description\" content=\"Uploading File to server using Servlet and JSP is a common task in Java web application. Before coding your Servlet or JSP to handle file upload request,\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2013\/08\/file-upload-example-in-servlet-and-jsp.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2013-08-06T07:00:23+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2014-02-23T21:28:18+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Javin Paul\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Javin Paul\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/08\\\/file-upload-example-in-servlet-and-jsp.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/08\\\/file-upload-example-in-servlet-and-jsp.html\"},\"author\":{\"name\":\"Javin Paul\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/dbfdaa2ce6e5fcb8b7b0b259a84fdb40\"},\"headline\":\"File Upload Example in Servlet and JSP\",\"datePublished\":\"2013-08-06T07:00:23+00:00\",\"dateModified\":\"2014-02-23T21:28:18+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/08\\\/file-upload-example-in-servlet-and-jsp.html\"},\"wordCount\":720,\"commentCount\":54,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/08\\\/file-upload-example-in-servlet-and-jsp.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/enterprise-java-logo.jpg\",\"keywords\":[\"JSP\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/08\\\/file-upload-example-in-servlet-and-jsp.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/08\\\/file-upload-example-in-servlet-and-jsp.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/08\\\/file-upload-example-in-servlet-and-jsp.html\",\"name\":\"File Upload Example in Servlet and JSP\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/08\\\/file-upload-example-in-servlet-and-jsp.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/08\\\/file-upload-example-in-servlet-and-jsp.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/enterprise-java-logo.jpg\",\"datePublished\":\"2013-08-06T07:00:23+00:00\",\"dateModified\":\"2014-02-23T21:28:18+00:00\",\"description\":\"Uploading File to server using Servlet and JSP is a common task in Java web application. Before coding your Servlet or JSP to handle file upload request,\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/08\\\/file-upload-example-in-servlet-and-jsp.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/08\\\/file-upload-example-in-servlet-and-jsp.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/08\\\/file-upload-example-in-servlet-and-jsp.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/enterprise-java-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/enterprise-java-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"java-interview-questions-answers\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/08\\\/file-upload-example-in-servlet-and-jsp.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"File Upload Example in Servlet and JSP\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/dbfdaa2ce6e5fcb8b7b0b259a84fdb40\",\"name\":\"Javin Paul\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/dc70a0e0b9d5c6614098936b017d6c79ed7f3e0c315a1e59d7d300e4c46d726c?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/dc70a0e0b9d5c6614098936b017d6c79ed7f3e0c315a1e59d7d300e4c46d726c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/dc70a0e0b9d5c6614098936b017d6c79ed7f3e0c315a1e59d7d300e4c46d726c?s=96&d=mm&r=g\",\"caption\":\"Javin Paul\"},\"description\":\"I have been working in Java, FIX Tutorial and Tibco RV messaging technology from past 7 years. I am interested in writing and meeting people, reading and learning about new subjects.\",\"sameAs\":[\"http:\\\/\\\/javarevisited.blogspot.com\\\/\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/javin-paul\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"File Upload Example in Servlet and JSP","description":"Uploading File to server using Servlet and JSP is a common task in Java web application. Before coding your Servlet or JSP to handle file upload request,","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2013\/08\/file-upload-example-in-servlet-and-jsp.html","og_locale":"en_US","og_type":"article","og_title":"File Upload Example in Servlet and JSP","og_description":"Uploading File to server using Servlet and JSP is a common task in Java web application. Before coding your Servlet or JSP to handle file upload request,","og_url":"https:\/\/www.javacodegeeks.com\/2013\/08\/file-upload-example-in-servlet-and-jsp.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2013-08-06T07:00:23+00:00","article_modified_time":"2014-02-23T21:28:18+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","type":"image\/jpeg"}],"author":"Javin Paul","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Javin Paul","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2013\/08\/file-upload-example-in-servlet-and-jsp.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/08\/file-upload-example-in-servlet-and-jsp.html"},"author":{"name":"Javin Paul","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/dbfdaa2ce6e5fcb8b7b0b259a84fdb40"},"headline":"File Upload Example in Servlet and JSP","datePublished":"2013-08-06T07:00:23+00:00","dateModified":"2014-02-23T21:28:18+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/08\/file-upload-example-in-servlet-and-jsp.html"},"wordCount":720,"commentCount":54,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/08\/file-upload-example-in-servlet-and-jsp.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","keywords":["JSP"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2013\/08\/file-upload-example-in-servlet-and-jsp.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2013\/08\/file-upload-example-in-servlet-and-jsp.html","url":"https:\/\/www.javacodegeeks.com\/2013\/08\/file-upload-example-in-servlet-and-jsp.html","name":"File Upload Example in Servlet and JSP","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/08\/file-upload-example-in-servlet-and-jsp.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/08\/file-upload-example-in-servlet-and-jsp.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","datePublished":"2013-08-06T07:00:23+00:00","dateModified":"2014-02-23T21:28:18+00:00","description":"Uploading File to server using Servlet and JSP is a common task in Java web application. Before coding your Servlet or JSP to handle file upload request,","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/08\/file-upload-example-in-servlet-and-jsp.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2013\/08\/file-upload-example-in-servlet-and-jsp.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2013\/08\/file-upload-example-in-servlet-and-jsp.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","width":150,"height":150,"caption":"java-interview-questions-answers"},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2013\/08\/file-upload-example-in-servlet-and-jsp.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"File Upload Example in Servlet and JSP"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/dbfdaa2ce6e5fcb8b7b0b259a84fdb40","name":"Javin Paul","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/dc70a0e0b9d5c6614098936b017d6c79ed7f3e0c315a1e59d7d300e4c46d726c?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/dc70a0e0b9d5c6614098936b017d6c79ed7f3e0c315a1e59d7d300e4c46d726c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/dc70a0e0b9d5c6614098936b017d6c79ed7f3e0c315a1e59d7d300e4c46d726c?s=96&d=mm&r=g","caption":"Javin Paul"},"description":"I have been working in Java, FIX Tutorial and Tibco RV messaging technology from past 7 years. I am interested in writing and meeting people, reading and learning about new subjects.","sameAs":["http:\/\/javarevisited.blogspot.com\/"],"url":"https:\/\/www.javacodegeeks.com\/author\/javin-paul"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/15958","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/251"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=15958"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/15958\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/112"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=15958"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=15958"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=15958"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}