<?xml version="1.0" encoding="ISO-8859-1"?>

<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
	<channel>
		<title>Java Programming Forums - The Java Community - Java Servlet</title>
		<link>http://www.javaprogrammingforums.com/</link>
		<description />
		<language>en</language>
		<lastBuildDate>Mon, 20 May 2013 06:17:22 GMT</lastBuildDate>
		<generator>vBulletin</generator>
		<ttl>60</ttl>
		<image>
			<url>http://www.javaprogrammingforums.com/images/misc/rss.png</url>
			<title>Java Programming Forums - The Java Community - Java Servlet</title>
			<link>http://www.javaprogrammingforums.com/</link>
		</image>
		<item>
			<title>commons-fileupload-1.2.1.jar Problems</title>
			<link>http://www.javaprogrammingforums.com/java-servlet/28959-commons-fileupload-1-2-1-jar-problems.html</link>
			<pubDate>Tue, 30 Apr 2013 13:42:10 GMT</pubDate>
			<description>Hi I have created a HTML form to upload multiple files through a servlet. I am using Tomcat 3.2 version and I have placed the...</description>
			<content:encoded><![CDATA[<div>Hi I have created a HTML form to upload multiple files through a servlet. I am using Tomcat 3.2 version and I have placed the commons-fileupload-1.2.1.jar and commons-io-1.4.jar in C:\Tomcat\lib directory. The servlet compiles but at run time generate exception of java.lang.NoClassDefFoundError: javax/servlet/http/HttpServletReques. I also copied the whole lib folder and put it into C:\Tomcat\webapps\root\web-inf folder but still the same status. I am totally stuck here.<br />
HTML Code from where I am accessing the servlet is <br />
<div class="bbcode_container">
                <div class="bbcode_description">Code :</div>
                <hr /><code class="bbcode_code"><div class="" style="font-family:monospace;"><pre style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&lt;form action=&quot;/servlet/FileUploadDemoServlet&quot; method=&quot;post&quot; enctype=&quot;multipart/form-data&quot;&gt;</pre></div></code><hr />
</div> <br />
I have placed the servlet in C:\Tomcat\webapps\root\web-inf\classes folder.<br />
Servlet code is as follows:<br />
<div class="bbcode_container">
                <div class="bbcode_description">Code :</div>
                <hr /><code class="bbcode_code"><div class="" style="font-family:monospace;"><pre style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
import java.io.*;
import java.util.*;
import java.io.IOException;
import java.io.File;
import java.util.List;
import java.util.Iterator;
&nbsp;
public class FileUploadDemoServlet extends HttpServlet {
    private static final long serialVersionUID = -3208409086358916855L;
&nbsp;
    protected void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
&nbsp;
        boolean isMultipart = ServletFileUpload.isMultipartContent(request);
&nbsp;
        if (isMultipart) {
            FileItemFactory factory = new DiskFileItemFactory();
            ServletFileUpload upload = new ServletFileUpload(factory);
&nbsp;
            try {
                List items = upload.parseRequest(request);
                Iterator iterator = items.iterator();
                while (iterator.hasNext()) {
                    FileItem item = (FileItem) iterator.next();
&nbsp;
                    if (!item.isFormField()) {
                        String fileName = item.getName();
&nbsp;
                        String root = getServletContext().getRealPath(&quot;/&quot;);
                        File path = new File(root + &quot;check/uploads&quot;);
                        if (!path.exists()) {
                            boolean status = path.mkdirs();
                        }
&nbsp;
                        File uploadedFile = new File(path + &quot;/&quot; + fileName);
                        System.out.println(uploadedFile.getAbsolutePath());
                        item.write(uploadedFile);
                    }
                }
            } catch (FileUploadException e) {
                e.printStackTrace();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}</pre></div></code><hr />
</div> Any help in this regard please.</div>

]]></content:encoded>
			<category domain="http://www.javaprogrammingforums.com/java-servlet/">Java Servlet</category>
			<dc:creator>sengreen</dc:creator>
			<guid isPermaLink="true">http://www.javaprogrammingforums.com/java-servlet/28959-commons-fileupload-1-2-1-jar-problems.html</guid>
		</item>
	</channel>
</rss>
