0
 package imageUplaod;

    import java.io.File;
    import java.io.IOException;
    import java.io.PrintWriter;

    import javax.servlet.ServletContext;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import com.oreilly.servlet.MultipartRequest;
    import com.oreilly.servlet.multipart.DefaultFileRenamePolicy;
    import java.util.Enumeration;



     public class UploadImage extends HttpServlet {
       private static final long serialVersionUID = 1L;

    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {        

    final int permitedSize = 314572800;  //~ 300 MB in bytes

    PrintWriter out = response.getWriter();
    response.setContentType("text/html;charset=UTF-8");
    response.setHeader("Cache-Control", "no-cache");
    response.setHeader("Pragma", "No-cache");
    response.setDateHeader("Expires",0);                       

    try{               
       String type = "";
       String name = "";
       String originalFilename = "";
       String extension1 = "";
       String extension2 = "";
       String filename = "";

       String strDirectory = "files";
       ServletContext sc=getServletContext();
       String uploadPath = sc.getRealPath("//WEB-INF//"+strDirectory+"//");

       MultipartRequest multipartRequest = new MultipartRequest(request, uploadPath, permitedSize, "ISO-8859-1", new DefaultFileRenamePolicy()); 

       Enumeration<String> files = multipartRequest.getFileNames();           

          while (files.hasMoreElements()) 
             { 
                 name = files.nextElement();
                 type = multipartRequest.getContentType(name); 
                 filename = multipartRequest.getFilesystemName(name); 
                 originalFilename = multipartRequest.getOriginalFileName(name);                 

                 extension1 = filename.substring(filename.length() - 4, filename.length());
                 extension2 = originalFilename.substring(originalFilename.length() - 4, originalFilename.length());

                 //return a File object for the specified uploaded file                   
                 File currentFile = multipartRequest.getFile(name);
                 InputStream inputStream = new BufferedInputStream(new FileInputStream(currentFile));
                 if(currentFile == null) {
                      out.println("There is no file selected!");
                      return;
                    }

                 //checking the file extensions according to the MIME types
                 if((type.equals("text/plain") || type.equals("image/gif") || type.equals("image/pjpeg")
                   || type.equals("image/x-png") || type.equals("image/jpeg"))) {       
                     //show a few details about the uploaded file        
                     out.println("file: "+filename);
                     out.println("type: "+type); 
                     out.println("size: "+currentFile.length());
                   } else {
                            out.println("\n Invalid format!");
                          } 
                 }                        

       }catch (Exception exception)
          {                     
      response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
      } finally { if(out != null) {out.close();} }      
    }       


    public UploadImage() {
        super();
        // TODO Auto-generated constructor stub
    }


    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        processRequest(request, response);

    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        processRequest(request, response);

    }
    }

       this is my index page:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><%@page
    language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <html>
    <head>
    <title>index</title>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    </head>
    <body>

    <h5>O'Reilly COS Upload</h5>
    <table>
    <tr>
     <td align="center">
      <form enctype="multipart/form-data" action="UploadImage" method="POST">
       Select the file to upload: 
       <input type="file" name="userfile">
       <input type="submit" value="Upload">
    </form>
    </td>
    </tr>
   </table>
   </body>
   </html>

when I run it I get following error:

      Error 404: javax.servlet.UnavailableException: SRVE0203E: Servlet [UploadImage]:  
     imageUplaod.UploadImage was found, but is missing another required class. SRVE0206E: 

This error typically implies that the servlet was originally compiled with classes which cannot be located by the server. SRVE0187E: Check your class path to ensure that all classes required by the servlet are present.SRVE0210I: This problem can be debugged by recompiling the servlet using only the classes in the application's runtime class path SRVE0234I:

  Application class path=[C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\java\lib;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\java\lib\dt.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\java\lib\htmlconverter.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\java\lib\ibmorbtools.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\java\lib\jconsole.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\java\lib\tools.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\profiles\was70profile1\classes;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\classes;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\lib;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\lib\EJBCommandTarget.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\lib\IVTClient.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\lib\OTiSConvertTime.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\lib\activation-impl.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\lib\aspectjrt.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\lib\bootstrap.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\lib\bsf-engines.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\lib\cimgr.ops.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\lib\commandlineutils.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\lib\commons-discovery.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\lib\databeans.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\lib\ffdcSupport.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\lib\htmlshell.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\lib\installver.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\lib\installxml.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\lib\iscdeploy.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\lib\ivblogbr.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\lib\j2ee.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\lib\jNative2ascii.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\lib\jacl.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\lib\jrom.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\lib\jsf-nls.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\lib\launchclient.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\lib\lmproxy.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\lib\mail-impl.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\lib\nif.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\lib\pc-appext.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\lib\pmirm4arm.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\lib\rrd-appext.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\lib\rsadbutils.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\lib\rsahelpers.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\lib\serviceadapter.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\lib\setup.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\lib\startup.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\lib\tcljava.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\lib\urlprotocols.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\lib\wses_dynaedge.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\lib\wsif-compatb.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\installedChannels;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\web\help;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\deploytool\itp\plugins\com.ibm.etools.ejbdeploy\runtime;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\deploytool\itp\plugins\com.ibm.etools.ejbdeploy\runtime\batch.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\deploytool\itp\plugins\com.ibm.etools.ejbdeploy\runtime\ejbdeploy.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\deploytool\itp\plugins\com.ibm.etools.ejbdeploy\runtime\ejbmapvalidate.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\derby\lib\derby.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\installedConnectors\sib.api.jmsra.rar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\profiles\was70profile1\installedConnectors\wmq.jmsra.rar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\profiles\was70profile1\installedConnectors\wmq.jmsra.rar\com.ibm.mq.commonservices.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\profiles\was70profile1\installedConnectors\wmq.jmsra.rar\com.ibm.mq.connector.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\profiles\was70profile1\installedConnectors\wmq.jmsra.rar\com.ibm.mq.headers.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\profiles\was70profile1\installedConnectors\wmq.jmsra.rar\com.ibm.mq.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\profiles\was70profile1\installedConnectors\wmq.jmsra.rar\com.ibm.mq.jmqi.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\profiles\was70profile1\installedConnectors\wmq.jmsra.rar\com.ibm.mq.jmqi.local.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\profiles\was70profile1\installedConnectors\wmq.jmsra.rar\com.ibm.mq.jmqi.remote.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\profiles\was70profile1\installedConnectors\wmq.jmsra.rar\com.ibm.mq.jmqi.system.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\profiles\was70profile1\installedConnectors\wmq.jmsra.rar\com.ibm.mq.jms.admin.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\profiles\was70profile1\installedConnectors\wmq.jmsra.rar\com.ibm.mq.pcf.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\profiles\was70profile1\installedConnectors\wmq.jmsra.rar\com.ibm.mqjms.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\profiles\was70profile1\installedConnectors\wmq.jmsra.rar\com.ibm.msg.client.commonservices.j2se.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\profiles\was70profile1\installedConnectors\wmq.jmsra.rar\com.ibm.msg.client.commonservices.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\profiles\was70profile1\installedConnectors\wmq.jmsra.rar\com.ibm.msg.client.jms.internal.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\profiles\was70profile1\installedConnectors\wmq.jmsra.rar\com.ibm.msg.client.jms.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\profiles\was70profile1\installedConnectors\wmq.jmsra.rar\com.ibm.msg.client.matchspace.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\profiles\was70profile1\installedConnectors\wmq.jmsra.rar\com.ibm.msg.client.provider.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\profiles\was70profile1\installedConnectors\wmq.jmsra.rar\com.ibm.msg.client.ref.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\profiles\was70profile1\installedConnectors\wmq.jmsra.rar\com.ibm.msg.client.wmq.common.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\profiles\was70profile1\installedConnectors\wmq.jmsra.rar\com.ibm.msg.client.wmq.factories.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\profiles\was70profile1\installedConnectors\wmq.jmsra.rar\com.ibm.msg.client.wmq.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\profiles\was70profile1\installedConnectors\wmq.jmsra.rar\com.ibm.msg.client.wmq.v6.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\profiles\was70profile1\installedConnectors\wmq.jmsra.rar\dhbcore.jar;C:\Program Files (x86)\IBM\SQLLIB\java\db2jcc.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\universalDriver\lib\db2jcc_license_cu.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7\profiles\was70profile1/properties;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7/properties;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7/lib/startup.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7/lib/bootstrap.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7/lib/jsf-nls.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7/lib/lmproxy.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7/lib/urlprotocols.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7/deploytool/itp/batchboot.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7/deploytool/itp/batch2.jar;C:\Program Files (x86)\IBM\SDP\runtimes\base_v7/java/lib/tools.jar;C:\Users\drunkendeath\IBM\rationalsdp\workspace\UploadImage\WebContent\WEB-INF\classes;C:\Users\drunkendeath\IBM\rationalsdp\workspace\UploadImage\WebContent]

So what is wrong here, can anybody explain? I have included all the .jars. There is no error in code.

4
  • possible duplicate of How to upload files to server using JSP/Servlet? Commented Jan 20, 2013 at 5:55
  • its not a dulicate,read the error Commented Jan 20, 2013 at 6:06
  • If you read the question/answer, it shows how to upload a file using a multipart request and that's what you are asking. If you use this method (that I particularly haven't seen anywhere in the net) then keep it, but there must be a good reason why that answer has all those votes on favor. Commented Jan 20, 2013 at 6:08
  • I have read it, it is not solving my problem. Please read my error. it says: Error 404: javax.servlet.UnavailableException: SRVE0203E: Servlet [UploadImage]: imageUplaod.UploadImage was found, but is missing another required class. SRVE0206E: This error typically implies that the servlet was originally compiled with classes which cannot be located by the server. SRVE0187E: Check your class path to ensure that all classes required by the servlet are present.SRVE0210I: Commented Jan 20, 2013 at 6:19

1 Answer 1

1

The error is telling you that one of your imports is not being found by Websphere. The only classes you are using are the O'Reilly ones and standard Java ones. It is highly unlikely that it is one of the Java classes that are not being found.

Make sure that the O'Reilly jar is in your WEB-INF/lib directory or place it into Websphere's classpath. If it is there, restart Websphere (standard fix it solution in the product I was on while I was at IBM).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.