Tomcat file upload

Hi, I'm having a problem with file upload.
I've try to use oReilly classes, but I've had problems.
So I've try to use a small package from com.bigfoot ( he's probably a student) for multipart form.
All works well with tomcat 4.0 on win2k.
When I deploy the application under Linux 7.2, Tomcat 4 and Apache ... problems begins :-(((((
During ServletInputStream reading, I think, something goes wrong. Some bytes are read ... then the stream seems to empty ... and the reading process crashes.
What can I do ????

I'm sorry I've change my account so look the newer message from alexdonato.

Similar Messages

  • File Upload using Tomcat 5.x Apache 2.x

    Hi,
    Once I updated my tomcat 5.x to apache 2.x and ran my upload jsp code using java api i wrote to upload file to server, all pictures or videos received seems distorted.. At first i thought of bit shift or something but when i upload a textfile all look right.. Anyone know what the heck is going on before i disect my code.
    thanks
    henry

    make sure your modjk logs don't have any errors.
    Here's a peice out of my httpd.conf
    #ADDed Oct 15,2003, seemed to remove modjk error
    AddType multipart/form-data .gif .png  .jpg .peg .jpeg .jpeI used to get strange modjk logged errors.
    Also did you compile jk2 from source???
    com.oreilly.servlet --- cos
    http://www.servlets.com/cos/index.html
    http://www.servlets.com/cos/cos-05Nov2002.zip
    But if my bit shift is correct wouldn't my regular textfile upload be distored?From what I remember, the problem is something to do with logical AND or OR, with the bits. Apache receives it fine, passess it through jk, and and either the most sig or least gets lost. Image data is critical as every bit counts, text file, you may not notice it(white space), or every nTH file upload might fail.
    here are the version numbers of software I use, and have compiled all from source.
    apache-httpd-2.0.47
    tomcat-4.1.27
    jk2-connectors-2.0.2

  • My file upload java application working fine in tomcat 7  but not working in weblogic 11

    Hi All,
    My  file upload  java application  successfully run in tomcat 7 . But  I could not run it in Weblogic 11.   Getting following error message   . Please help.
    Please contact your administrator.org.springframework.beans.NullValueInNestedPathException: Invalid property 'fileData[0]' of bean class [com.techm.util.UploadItem]: Cannot access indexed value in property referenced in indexed property path 'fileData[0]': returned null
      at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:681)
      at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:651)
      at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:78)
      at org.springframework.validation.DataBinder.applyPropertyValues(DataBinder.java:587)
      at org.springframework.validation.DataBinder.doBind(DataBinder.java:489)
      at org.springframework.web.bind.WebDataBinder.doBind(WebDataBinder.java:149)
      at org.springframework.web.bind.ServletRequestDataBinder.bind(ServletRequestDataBinder.java:110)
      at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter$ServletHandlerMethodInvoker.doBind(AnnotationMethodHandlerAdapter.java:566)
      at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveHandlerArguments(HandlerMethodInvoker.java:213)
      at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:132)
      at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:326)
      at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:313)
      at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:875)
      at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:807)
      at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
      at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:511)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
      at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
      at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
      at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:301)
      at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
      at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
      at oracle.security.jps.ee.http.JpsAbsFilter$1.run(JpsAbsFilter.java:119)
      at java.security.AccessController.doPrivileged(Native Method)
      at oracle.security.jps.util.JpsSubject.doAsPrivileged(JpsSubject.java:324)
      at oracle.security.jps.ee.util.JpsPlatformUtil.runJaasMode(JpsPlatformUtil.java:460)
      at oracle.security.jps.ee.http.JpsAbsFilter.runJaasMode(JpsAbsFilter.java:103)
      at oracle.security.jps.ee.http.JpsAbsFilter.doFilter(JpsAbsFilter.java:171)
      at oracle.security.jps.ee.http.JpsFilter.doFilter(JpsFilter.java:71)
      at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
      at oracle.dms.servlet.DMSServletFilter.doFilter(DMSServletFilter.java:163)
      at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
      at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3730)
      at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3696)
      at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
      at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
      at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2273)
      at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2179)
      at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1490)
      at weblogic.work.ExecuteThread.execute(ExecuteThread.java:256)
      at weblogic.work.ExecuteThread.run(ExecuteThread.java:221)

    What version of spring are you using in tomcat?
    What version of WLS are you using.
    What JDK are you using in both environments?
    Is the issue random? or can you reproduce it at will?
    Thanks
    Luz

  • File upload using commons-upload-file and tomcat 5.5

    Hi,
    This is my first post and I hope that I post it at the right place.
    I'm trying to upload a file using commons-upload-file and tomcat 5.5.
    Is there a way to prevent submitting a big file, If I detect that the file being uploaded exceed a limit that I have fixed ?
    i.e. I check the request length, if it's bigger than 1meg I cancel the whole thing and the big file is not transferred.
    The problem that I get at the moment is that it seems that the file is transferred even if I close request inputstream or response outputstream. Any help would be appreciated !
    Thank you
    Redgy

    Well here is a snippet of my code:
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
            long maxSize = 50000;
            boolean isMultipart = ServletFileUpload.isMultipartContent(request);
            if(isMultipart){
                // Create a new file upload handler
                ServletFileUpload upload = new ServletFileUpload();
                upload.setSizeMax(maxSize);
                try {
                    upload.parseRequest(request);
                } catch (FileUploadException ex) {
                    ex.printStackTrace();
                    request.getInputStream().close();
                    response.getWriter().print("blah");
                    response.sendError(response.SC_INTERNAL_SERVER_ERROR);
                    response.getOutputStream().close();
        }If the file is bigger than 50kb, it Throws the FileUploadException.
    But whatever I do, It seems that there is still a connection between my browser and tomcat.. any clue ?
    thanks
    Edited by: redgyx on Jan 31, 2008 6:17 AM

  • HELP! File Upload Servlet and Internet Explorer

    Hello people. I hope this is an easy problem to solve...
    I have a servlet upload program that works using Mozilla browser (www.mozilla.org), but for some reason it doesn't work using Microsoft IE. The servlet is also using the servlet upload API from Apache (commons).
    I'm using IE version 6.0.2800.1106 in a Win98SE host computer. I get a cannot find path specified error message (see below). At work, I also get the same error message using IE, but don't know what version. The OS is XP. Unfortunately, at work, I can't install Mozilla browser (or any software-company policy) to see if Mozilla works there too. I would've like to have tested to see if the upload program worked on Mozilla on a truly remote computer.
    So I figured, it must be a IE configuration issue, but darn it!! I began by resetting IE to default settings, but still have the problem, I played around with several different combinations of settings in "Tools"-->"Internet Options...", and I still get the error message. Someone PLEASE HELP ME!!!
    Dunno, if it will help, I've also pasted the upload servlet source code below and the html file that's calling the upload servlet, but you still need the Apache commons file upload API.
    Trust me on this one folks, for some reason it works for Mozilla, but not for IE. With IE, I can at least access web server, and therefore, the html file that calls the upload servlet , so I don't think it's a Tomcat configuration issue (version 5.0). I actually got the code for the file upload servlet from a book relatively new in the market (printed in 2003), and it didn't mention any limitations as far as what browser to use or any browser configuration requirements. I have e-mailed the authors, but they probably get a ton of e-mails...
    Anyone suggestions?
    Meanwhile, I will try to install other free browsers and see if the file upload program works for them too.
    ERROR MESSAGE:
    "HTTP Status 500 -
    type Exception report
    message
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    javax.servlet.ServletException: C:\TOMCAT\webapps\MyWebApps\files\C:\WINDOWS\Desktop\myfile.zip (The system cannot find the path specified)
         com.jspbook.FileUploadCommons.doPost(FileUploadCommons.java:43)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
    root cause
    java.io.FileNotFoundException: C:\TOMCAT\webapps\MyWebApp\files\C:\WINDOWS\Desktop\myfile.zip (The system cannot find the path specified)
         java.io.FileOutputStream.open(Native Method)
         java.io.FileOutputStream.(FileOutputStream.java:176)
         java.io.FileOutputStream.(FileOutputStream.java:131)
         org.apache.commons.fileupload.DefaultFileItem.write(DefaultFileItem.java:392)
         com.jspbook.FileUploadCommons.doPost(FileUploadCommons.java:36)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
    note The full stack trace of the root cause is available in the Tomcat logs.
    Apache Tomcat 5.0.16"
    FILE UPLOAD SERVLET source code:
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import org.apache.commons.fileupload.*;
    import java.util.*;
    public class FileUploadCommons extends HttpServlet {
    public void doPost(HttpServletRequest request,
    HttpServletResponse response)
    throws IOException, ServletException {
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    out.println("<html>");
    out.print("File upload success. <a href=\"/MyWebApp/files/");
    out.print("\">Click here to browse through all uploaded ");
    out.println("files.</a><br>");
    ServletContext sc = getServletContext();
    String path = sc.getRealPath("/files");
    org.apache.commons.fileupload.DiskFileUpload fu = new
    org.apache.commons.fileupload.DiskFileUpload();
    fu.setSizeMax(-1);
    fu.setRepositoryPath(path);
    try {
    List l = fu.parseRequest(request);
    Iterator i = l.iterator();
    while (i.hasNext()) {
    FileItem fi = (FileItem)i.next();
    fi.write(new File(path, fi.getName()));
    catch (Exception e) {
    throw new ServletException(e);
    out.println("</html>");
    public void doGet(HttpServletRequest request,
    HttpServletResponse response)
    throws IOException, ServletException {
    doPost(request, response);
    HTML PAGE that calls the upload servlet:
    <html>
    <head>
    <title>Example HTML Form</title>
    </head>
    <body>
    <p>Select a file to upload or browse
    currently uploaded files.</p>
    <form action="http://##.##.##.####/MyWebApp/FileUploadCommons"
    method="post" enctype="multipart/form-data">
    File: <input type="file" name="file"><br>
    <input value="Upload File" type="submit">
    </form>
    </body>
    </html>
    Thanks in advance for any assistance.
    -Dan

    I'm guessing what is happening is that Mozilla tells the servlet "here comes the file myfile.zip". The servlet builds a file name for it:
        String path = sc.getRealPath("/files");
        // path is now C:\TOMCAT\webapps\MyWebApps\files\
        fi.write(new File(path, fi.getName()));
        // append myfile.zip to "path", making it C:\TOMCAT\webapps\MyWebApps\files\myfile.zipIE, however, tells "here comes the file C:\WINDOWS\Desktop\myfile.zip". Now imagine what the path+filename ends up being...
    So what you want to do is something along the lines of (assuming Windoze):
    public static String basename(String filename)
        int slash = filename.lastIndexOf("\\");
        if (slash != -1)
            filename = filename.substring(slash + 1);
        // I think Windows doesn't like /'s either
        int slash = filename.lastIndexOf("/");
        if (slash != -1)
            filename = filename.substring(slash + 1);
        // In case the name is C:foo.txt
        int slash = filename.lastIndexOf(":");
        if (slash != -1)
            filename = filename.substring(slash + 1);
        return filename;
        fi.write(new File(path, basename(fi.getName()));
        ....You can make the file name check more bomb proof if security is an issue. Long file names trying to overflow something in the OS, NUL characters, Unicode, forbidden names in Windos (con, nul, ...), missing file name, ...

  • File Upload using PRC API's

    Guys,
    I am trying to upload a new document using PRC API's. Below is required code snippet that i am using.
    IRemoteDocument remoteDoc = documentManager.createRemoteDocument(folderID,dataSourceID,document.getPath()); remoteDoc.setOverrideName(document.getName()); remoteDoc.setOverrideDescription(document.getDescription()); remoteDoc.setType("http://www.plumtree.com/dtm/mime", document.getFileType());int docID = -1;docID = remoteDoc.save();
    dataSourceID - ID of my file upload datasource , document - is my java object which has all the document related properties such as , name , description , MIME type of document etc..Below is different document path's(scenarios) that I have triedc:\work\sample.txt\\servername\work\sample.txthttp:\\appserver:7001\appName\uploadfiles\sample.txt
    When I execute this code from my application i get a below error.
    com.plumtree.remote.prc.PortalException: null; nested exception is: java.rmi.RemoteException: Error in function PTDataSource.ImportDocument(vDocumentLocationBagAsXML == '<?xml version="1.0" encoding="ucs-2"?><PTBAG V="1.1" xml:space="preserve"><I N="PTC_DTM_SECT">1001</I><S N="PTC_DOC_ID">application/msword</S><S N="PTC_UNIQUE">\\PHUSEH-L33664.NA.novartis.net\work\sample.doc</S></PTBAG>', lDocumentTypeID == 100, pCard == com.plumtree.server.impl.directory.PTCard@c27b6f, bSummarize == false, pProvider == null): Error in function PTDataSource.ImportDocument (vDocumentLocationBagAsXML == <?xml version="1.0" encoding="ucs-2"?><PTBAG V="1.1" xml:space="preserve"><S N="PTC_DOC_ID">application/msword</S><I N="PTC_DTM_SECT">1001</I><S N="PTC_UNIQUE">\\PHUSEH-L33664.NA.novartis.net\work\sample.doc</S></PTBAG>, lDocumentTypeID == 100, pCard == com.plumtree.server.impl.directory.PTCard@c27b6f, bSummarize == false, pProvider == null): SOAP fault: faultcode='soapenv:Server.userException' faultstring='java.lang.NullPointerException' at com.plumtree.remote.prc.DocumentWrapper.save()
    Below is my environment.Plumtree is running on Weblogic 8.1 (Solaris OS) , ptupload webservice is running on weblogic8.1 solaris,My upload document portlet is running on weblogic 8.1 (Windows OS)
    If anyone has any working sample code please send it to my ID [email protected] or else please upload it here.Thank You ,
    Dan.

    make sure your modjk logs don't have any errors.
    Here's a peice out of my httpd.conf
    #ADDed Oct 15,2003, seemed to remove modjk error
    AddType multipart/form-data .gif .png  .jpg .peg .jpeg .jpeI used to get strange modjk logged errors.
    Also did you compile jk2 from source???
    com.oreilly.servlet --- cos
    http://www.servlets.com/cos/index.html
    http://www.servlets.com/cos/cos-05Nov2002.zip
    But if my bit shift is correct wouldn't my regular textfile upload be distored?From what I remember, the problem is something to do with logical AND or OR, with the bits. Apache receives it fine, passess it through jk, and and either the most sig or least gets lost. Image data is critical as every bit counts, text file, you may not notice it(white space), or every nTH file upload might fail.
    here are the version numbers of software I use, and have compiled all from source.
    apache-httpd-2.0.47
    tomcat-4.1.27
    jk2-connectors-2.0.2

  • JSP : latest  JSTL, File Upload from web form Client to Server Question!

    I understand that within a JSP, It is possible to read a file from the Client by opening a Stream somehow.
    How do I code, within jsp/servlet (non tag) java code inside <% %>
    blocks, WITHOUT openening a new connection to the URL, an InputStream from a client web browser form, from a file upload coded using
    <input type="file" name="file1"/> ?
    I have previously achieved this quite simply with a FileInputStream
    with the previous version of JSTL.
    How may I do this with the latest version of JSTL, with this index.jsp?
    -with a simple text file.
    -with a Binary file (with DataInputStream)?
    <%--
    Document : index
    Created on : 27/01/2009, 3:08:32 PM
    Author : Zachary Mitchell
    --%>
    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
    </head>
    <body>
    <h1 align="center">Hello World!</h1>
    <form name="form1" method ="POST" >
    <table align="center">
    <tr>
    <td>
    <input name="file1" type="file" align="center"></input>
    </td>
    </tr>
    <tr>
    <td>
    <input type="submit" value="submit" action="index.jsp" ></input>
    </td>
    </tr>
    </table>
    </form>
    <!--*********************************************************************** -->
    <%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
    <%@page import = "java.io.*" %>
    <c:if test="${pageContext.request.method=='POST'}">
    <%
    File fileName = new File(request.getParameter("file1"));
    out.println(fileName.toString());
    FileInputStream stream = new FileInputStream(fileName);
    out.println(stream.toString());
    %>
    </c:if>
    <!--*********************************************************************** -->
    </body>
    </html>

    If I have:
    <!-- ***********************************************************************************-->
    <form name="form1" method="POST" enctype="multipart/form-data">
    <input name="file1" type="file"/>
    <input name="submit1" type="submit" value="Submit" action="index.jsp"/>
    </form>
    <!-- ***********************************************************************************-->
    and run this in an index.jsp, use browse to select my text file, and click SUBMIT.
    I can use:
    InputStreamReader reader = new InputStreamReader(new DataInputStream(request.getInputStream()))
    BufferedReader bufferedReader = new BufferedReader(reader);
    bufferedReader.readLine();...
    However, these is some HTML/POST related content around what multiple readLine();
    calls return.
    Is there an easy way, like using "${param.file1}",
    aside from [http://commons.apache.org/fileupload/|http://commons.apache.org/fileupload/],
    maybe using servlet style code, to get the File contents from a remote Client,
    to the remote Server servlet engine, AVOIDING ANY SUPERFLUOUS CONTENT,
    using version 1.12 of the JSTL, JSP 2.0,Tomcat 6?
    Just politely, yes, no, and how?
    Edited by: Zac1234 on Jan 29, 2009 3:27 AM
    Edited by: Zac1234 on Feb 1, 2009 8:29 PM

  • Creating Progress Bar for File Upload

    Hi, I'm trying to implement a progress bar indicator for a file upload in WebDynpro, without very good results.
    I'm using a fileupload UI element, a TimerTrigger and a ProgressIndicator UI elements for this purpose.
    It seems that using the fileupload UI element the iview is locked during the file upload, and therefore it prevents for the timer triggered action to be performed (this action updates the progress bar).
    Additionally I havent been able to capture the transfered bytes from the upload. Maybe I'm using the wrong elements?
    How could I achieve this. Has anyone done it?
    I would really appreciate all the help I could get.
    Homer Vargas

    Hi,
    Can anyone please tell me the way to upload file from client system to server.
    The code i have is as follows:-
    Jsp:-
    function saveImage(){
         //projectname.javafilename
         var strStatus = "save";
         document.saveImageForm.action="/irj/servlet/prt/portal/prtroot/TestXML.TextImageLink?frmstatus="+ strStatus;
         document.saveImageForm.method="post";
         document.saveImageForm.submit();     
    <form name="saveImageForm" encrypt="multipart/form-data">
    <table width="388" cellpadding="1" cellspacing="1" bgcolor="#F0F0F0" border='0'>
           <tr>
                 <td><font color="blue" face="verdana" size="2">IMAGE:</font></td><td><input id="image" type="file" name="image" value=""/></td>
         </tr>
    <tr>
         <td><input type="submit" name="submit" value="Submit" onclick="saveImage();"/></td>
         </tr>
    </table>
    </form>
    now i am not getting what to write in java file
    using IPortalComponentRequest.
    Using the jsp file upload in tomcat is working but here it is not working
    please help meee
    Thanks in Advance
    Regards
    Sirisha

  • File upload with non-ascii name

    I'm designing a system that includes file-uploads. My problem is that any non-ascii chars in the filename are encoded strangely when saved. &auml; is encoded to a&#778; etc.
    I use Tomcat with the -Dfile.encoding="UTF-8" in the Catalina file. I get the same result despite method; my own implementation, apache commons or Javazoom's uploadBean. All the JSP charset parameters are set.
    Any ideas?

    Hi amitads,
    I'm sure u've used Java enough. Also, u must have learned about the \ (backslash) escape character ?
    So, if u want to include a string like a single quote, u can write \' and for a double quote u can write \".
    Try this ... I'm sure it will help.
    Keep me posted.
    Cheers !!
    Sherbir.

  • Problem in file upload......

    hi
    i had problem in file upload to server.
    i gave a absolute path to stored location that is working.
    but i tried to give relative path of the server that is not working
    plz help me to this problem..
    how to give relative path to Tomcat server...

    FilePart filePart = (FilePart) part;
              String fileName = filePart.getFileName();
              if (fileName != null) {
                   // the part actually contained a file
    String path= getServletContext().getRealPath("/empimages");
    File dir = new File(path);
                   long size = filePart.writeTo(dir);
                   }

  • File upload problem. Can't write to server

    Hi guys,
    I am currently trying to upload some images to the server I am using but I can't succeed.
    I am using a form consisting of 3 text fields 1 textarea and an upload form.
    The whole thing is working fine on my localhost . All the items are being inserted to the database and the files saved to the path.
    But when I try to upload to the commercial server even though the text field are being read and inserted to database the files just can't!!
    my tree structure is
    /home/domain/www-domain/webapps
    and that's what I am getting when using
    getServletContext().getRealPaththe full line for getting the real path is
    FileWriter fw2 = new FileWriter(getServletContext().getRealPath("//upload"+fileName+".jsp")); I am using tomcat 4.0 and all the other servlets are working just fine
    as this one apart from the FileWriting thing?
    am I doing something wrong with the getServletContext thing?
    And if so, why is it working just fine on my pc?
    I am only suspecting that I am not getting the path correctly
    I want to store the images under
    webapps/upload/images
    but it doesn't work even when I am trying to store under webapps (root directory)
    Is there any way that I am not getting permission to write to the server??
    Any help is highly appreciated!!
    cheers

    the thing is that I am not getting any exception back to my browser> some of the values are inserted into the database (the ones that are not referring to any uploded items). i guess i have to do a print.stacktrace but I am not sure at which point...
    ok I am posting the full code to give you an idea. Your interest is much appreciated , thank you
    import java.sql.*;
    import java.text.ParsePosition;
    import java.text.SimpleDateFormat;
    import java.util.*;
    import java.util.Date;
    import gr.cretasport.util.*;
    import org.apache.commons.fileupload.*;
    import java.awt.Image;
    import java.io.*;
    import javax.servlet.RequestDispatcher;
    import javax.servlet.ServletConfig;
    import javax.servlet.ServletContext;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest ;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.http.HttpSession;
    * @author myron.veligradis
    * 17/09/2005
    * TODO To change the template for this generated type comment go to
    * Window - Preferences - Java - Code Style - Code Templates
    public class InsertArticle extends HttpServlet{
      * global variables
    String fieldName;
    Image imageIn;
    Resize rsImg = new Resize();
    Mirror mrImg = new Mirror();
    //ImageProcess ImPr = new ImageProcess();
    Date curDate;
    String datecur;
    String inputtext;
    BufferedWriter bw;
    String aRString ;
    String photoPath;
    File savedFile;
    String txtPath;
    String txtPathFullText;
    String author;
    String eidos;
    String kathgoriaID;
    String title;
    String rating;
    String kathgoria;
    String keimeno;
    String keimenoRest;
    String fullKeimeno;
    String hmeromhniaD;
    final String jspPrefix="<%@ page contentType=\"text/html; charset=iso-8859-7\" language=\"java\"  errorPage=\"\" %>";
    Connection con=null;
    Statement statement = null;
    ResultSet rs, rs1 = null;
    int kathgoriaIDInt;
    int ratingInt;
    public void init(ServletConfig conf) throws ServletException  {
      super.init(conf);
    public void doPost (HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException, UnsupportedEncodingException {
    //  try {
    //   req.setCharacterEncoding("iso-8859-7");
    //   catch (UnsupportedEncodingException uee)
      boolean isMultipart = FileUpload.isMultipartContent(req);
      HttpSession session = req.getSession();
      ServletContext sc = getServletContext();
       * GET THE FILE NAME
      curDate=new Date();
      datecur = curDate.toString ();
        String fileName = datecur.replaceAll("\\W","_");
        String strDate = curDate.toString();
        SimpleDateFormat formatter= new SimpleDateFormat ("EEE MMM dd hh:mm:ss zzz yyyy");
      Date date = formatter.parse(strDate,new ParsePosition(0));
      hmeromhniaD = new SimpleDateFormat("yyyy-MM-dd").format(date);
       *  GET THE PARAMETERS
       *  FILE UPLOAD *******************************************************
      System.out.println(isMultipart);
      DiskFileUpload upload = new DiskFileUpload();
      try {
       req.setCharacterEncoding("iso-8859-7");
       List items = upload.parseRequest(req);
       Iterator itr = items.iterator();
       while(itr.hasNext()) {
        FileItem item = (FileItem) itr.next();
    //    String articleTitle = new String(req.getParameter("articleTitle").getBytes("iso-8859-1"),"iso-8859-7");
       // check if the current item is a form field or an uploaded file
         if(item.isFormField()) {
         // get the name of the field
         // if it is name, we can set it in request to thank the user
         if (item.getFieldName().equals("author")) {
                author = new String(item.getString().getBytes("iso-8859-1"),"iso-8859-7");
         if (item.getFieldName().equals("eidos")) {
                eidos = new String( item.getString().getBytes("iso-8859-1"),"iso-8859-7");
         if (item.getFieldName().equals("keimeno")) {
                keimeno =item.getString();
                FileWriter fw1 = new FileWriter(getServletContext().getRealPath("webapps//upload"+"pro_"+fileName +".jsp"));
           fw1.write(jspPrefix+"<html><body>"+keimeno+"</body></html>");
           fw1.close();
           txtPath = ("upload/text/"+"pro_"+fileName+".jsp");
         if (item.getFieldName().equals("keimenorest")) {
                keimenoRest =item.getString();
                FileWriter fw2 = new FileWriter(getServletContext().getRealPath("//upload"+fileName+".jsp"));
           fw2.write(jspPrefix+"<html><body>"+keimeno+" "+keimenoRest+"</body></html>");
           fw2.close();
           txtPathFullText = ("upload/text/fulltext/"+fileName+".jsp");
         if (item.getFieldName().equals("title")) {
               // title = new String(item.getString().getBytes("iso-8859-1"),"iso-8859-7");
                System.out.println ("titlos "+title);
                title=getServletContext().getRealPath("webapps//upload");
         if (item.getFieldName().equals("rating")) {
                rating = item.getString();
         if (item.getFieldName().equals("kathgoriaID")) {
                kathgoriaID = item.getString();
       else {
        // the item must be an uploaded file save it to disk. Note that there
        // seems to be a bug in item.getName() as it returns the full path on
        // the client's machine for the uploaded file name, instead of the file
        // name only. To overcome that, I have used a workaround using
        // fullFile.getName().
        File fullFile  = new File(item.getName()); 
        //check if input file is actually an image
        if ( item.getName().toLowerCase().endsWith(".jpg") ||
        item.getName().toLowerCase().endsWith(".gif") ||
        item.getName().toLowerCase().endsWith(".bmp"))
         File temp = new File(getServletContext().getRealPath("webapps//upload")," temp.jpg");
         item.write(temp);
         //to class Resize pernei 2 inputs, to file kai to path string
         rsImg.resizeImage(temp,getServletContext().getRealPath("webapps//upload"+fileName+".jpg"));
         //to class Mirror pernei kai ayto 2 inputs, to file poy exei dhmiourgithei apo panw
         //pou to kanei overwrite epeidh pernoun to idio onoma me to time stamp
         Mirror.mirrorImage(new File(getServletContext().getRealPath("webapps"+fileName+".jpg")),
           getServletContext().getRealPath("webapps//upload"+fileName+".jpg"));
         System.out.println("upload/images/"+fileName+".jpg");
      kathgoriaIDInt= new Integer(kathgoriaID).intValue();
      ratingInt   = new Integer(rating).intValue();
       * HTML UPLOAD
      catch (Exception fe) {
      //get the string names to insert to database
      photoPath="upload/images/"+fileName+".jpg";
       * INSERT THE DATA INTO THE DATABASE
      InsertToDatabase();
      String url="/insertarticle.jsp";
      RequestDispatcher rd = sc.getRequestDispatcher(url);
      rd.forward(req,res);
    //res.sendRedirect( res.encodeRedirectURL( "indextest.jsp "));
    public void InsertToDatabase() {
      try {
       con=null;
       statement = con.createStatement();
       String insertprefix = "insert into articles(eidos,photopath,textpath,textpathfull,title,author,dateen,rating, kathgoriaID) VALUES"
         + "('" + eidos.trim() +"','" + photoPath.trim()  + "','"   +
         txtPath + "','" + txtPathFullText + "','" +title + "','"+ author + "','"+ hmeromhniaD + "','"+ ratingInt+ "','"
         +kathgoriaIDInt + "')";
       statement.execute(insertprefix);
       statement.close();
       con.close();
       catch (Exception e)
    }

  • File Upload using Flash8

    I want to create a Flash page which allows user to upload
    files. The scripting language for the server would be JSP using
    tomcat.
    Can any1 tell me where I could find a tutorial in this
    matter, coz...I see php and flash interaction all around the net??
    If some1 could post the code on JSP for doing this it would hep me
    completely, since I have already done the Flash 8 upload code as
    follows:

    FileReference.upload in JSP problem
    Help !!!
    We've succesfully implemented file upload via flash in jsp
    tomcat (using FileReference.upload() in actionscript 2.0 ), but for
    some reason, parameters posted in the url to the file upload
    handling script (ej. "uploadScript.jsp?id=1") are lost, ie: the
    id=1 is lost.
    To double check flash correctly sending params , we've
    implemented the same flash object in php and parameters are posted
    fine.
    Any Ideas, I'm desperate.
    thanks.
    cC

  • Jakarta Commons -- File Upload does not work with Application Server

    Hi ALl,
    I tried Jakarta Commons file upload. In the netbeans, I copied the common jar files "commons-io-1.2.jar" and "commons-fileupload-1.1.1.jar" in the
    netbeans-5.5\enterprise3\apache-tomcat-5.5.17\common\lib and set the class paths. It is working correctly when I compile and run from the netbeans. However, when I deployed in Sun Application Server PE 9.0, I am receiving the following errors. In Sun application I copied the above jars files to "C:\Sun\AppServer\jdk\jre\lib\ext"..
    I have read in several postings that it does not work this way but could find any solution. Any idea will be greatly appreciated.
    HTTP Status 500 -
    type Exception report
    message
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    javax.servlet.ServletException: java.lang.NoClassDefFoundError: javax/servlet/ServletInputStream
         org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:930)
         org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:863)
         org.apache.jsp.fileUpload_jsp._jspService(fileUpload_jsp.java:109)
         org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:353)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:409)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:317)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
         com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:73)
         com.sun.enterprise.web.VirtualServerPipeline.invoke(VirtualServerPipeline.java:120)
         org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:231)
         com.sun.enterprise.web.connector.grizzly.ProcessorTask.invokeAdapter(ProcessorTask.java:667)
         com.sun.enterprise.web.connector.grizzly.ProcessorTask.processNonBlocked(ProcessorTask.java:574)
         com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(ProcessorTask.java:844)
         com.sun.enterprise.web.connector.grizzly.ReadTask.executeProcessorTask(ReadTask.java:287)
         com.sun.enterprise.web.connector.grizzly.ReadTask.doTask(ReadTask.java:212)
         com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:252)
         com.sun.enterprise.web.connector.grizzly.WorkerThread.run(WorkerThread.java:75)
    root cause
    java.lang.NoClassDefFoundError: javax/servlet/ServletInputStream
         org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:116)
         org.apache.jsp.fileUpload_jsp._jspService(fileUpload_jsp.java:76)
         org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:353)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:409)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:317)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
         com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:73)
         com.sun.enterprise.web.VirtualServerPipeline.invoke(VirtualServerPipeline.java:120)
         org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:231)
         com.sun.enterprise.web.connector.grizzly.ProcessorTask.invokeAdapter(ProcessorTask.java:667)
         com.sun.enterprise.web.connector.grizzly.ProcessorTask.processNonBlocked(ProcessorTask.java:574)
         com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(ProcessorTask.java:844)
         com.sun.enterprise.web.connector.grizzly.ReadTask.executeProcessorTask(ReadTask.java:287)
         com.sun.enterprise.web.connector.grizzly.ReadTask.doTask(ReadTask.java:212)
         com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:252)
         com.sun.enterprise.web.connector.grizzly.WorkerThread.run(WorkerThread.java:75)
    note The full stack trace of the root cause is available in the Sun Java System Application Server Platform Edition 9.0 logs.
    Sun Java System Application Server Platform Edition 9.0
    Thank you,
    --Sam                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Hi All,
    I solved this few minutes after I posted this question. Thought I should share with everybody, just in case some one else need it.
    I copied these three files in the folder C:\Sun\AppServer\jdk\jre\lib\ext
    1. servelet-api.jar
    2. commons-io-1.2.jar
    3. commons-fileupload-1.1.1.jar
    No need to set any class path.
    Thanks

  • File upload program by jsf

    I am doing one file upload program using
    <af:inputFile label="File to Upload" columns="90"
    value="#{FileProcessor.uploadedFile}"/>
    component..
    in Jdeveloper 11g i am getting the correct result,
    but when i'm tryin to run it in Jdeveloper jdevstudio10131 it is giving this error.
    java.io.EOFException: Per-request disk space limits exceeded. at oracle.adfinternal.view.faces.webapp.UploadedFileImpl.loadFile(UploadedFileImpl.java:187) at
    i want this file upload application to run in ecplise..but there it is not working..do i need so some to import some jar files??
    tomat 5.0 i'm using there..
    Or is there any otherway to upload file using jsf component which should work in eclipse-tomcat enviornment also..
    please help
    thanks

    Mr BalusC,
    Yes Iam talking about a custom made upload component. The fileupload tutorials u send are good but my requirement is not meeting them. Among my requirements one is mutilple file uploads in the single view page. This is possible at present with my custom upload componet. Only if the problem gets solved. Any way once again please think on my problem and give your solution on it.
    Here is my problem:
    The problem is I have to access the components from view page which this kind of requirement possible in jsp by request parsing which results the key value pairs of the form components. This same thing/way I should get in backing bean from JSF view page.
    The solution I want may like as follows.
    Note this code is incorrect and wrong but for to understand my requirement.
    someobject.getComponentIdValue("clientID"); which returns a string value as d:\images\Tutle.jpg
    The clientID is upload file component' Id . In the request it may be the key associated with value as file complete path. By this kind of way my upload filter is able to get the orignal file. Ok i need this in my  backing bean to get the orignal filename to insert into the database. Please for this give the solution or reply.many thanx,
    vijaycanaan.

  • Multiple File Uploads

    Hello,
    Can anyone provide me with sample code of how to upload multiple fies on Apache-Tomcat using Servlet. Also how to do if user has to specifiy the directory path to upload it ???
    Thanks for your time !!

    I have made use of jakartas commons FileUpload classes for the uploading purpose which i find much easier
    here is a small example in which uploading is done using a servlet
    here is my html file
    <html>
    <form method="post" action="/uploadFile" enctype="multipart/form-data">
    Name
    <input type="text" name="uname"/>
    File
    <input type="file" name="upfile"/>
    <input type="file" name="upfile1"/>
    <input type="submit"/>
    </form>
    </html>
    here is my servlet
    package mypack;
    import java.io.File;
    import java.io.IOException;
    import java.util.Iterator;
    import java.util.List;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import org.apache.commons.fileupload.DiskFileUpload;
    import org.apache.commons.fileupload.FileItem;
    import org.apache.commons.fileupload.FileItemFactory;
    import org.apache.commons.fileupload.FileUpload;
    import org.apache.commons.fileupload.FileUploadException;
    * @author sm23772
    * TODO To change the template for this generated type comment go to
    * Window - Preferences - Java - Code Style - Code Templates
    public class UploadFile extends HttpServlet {
         public void doPost(HttpServletRequest req,HttpServletResponse res)
         try{
              FileUpload fup=new FileUpload();
              boolean isMultipart = FileUpload.isMultipartContent(req);
    //          Create a new file upload handler
              System.out.println(isMultipart);
              DiskFileUpload upload = new DiskFileUpload();
    //          Parse the request
              List items = upload.parseRequest(req); // give u the list of items in the form
              Iterator iter = items.iterator();
              while (iter.hasNext()) {
              FileItem item = (FileItem) iter.next();
              if (item.isFormField()) {
              System.out.println("its a field");//it is a simple field
              } else {
              System.out.println("its a file");
              File cfile=new File(item.getName());
              System.out.println(cfile.getName());
              System.out.println(getServletContext().getRealPath("/"));// this will give u the path upto ROOT folder..if u want to put inside ur own forlder u can give the location inside the quotes
              File tosave=new File(getServletContext().getRealPath("/"),cfile.getName());
              item.write(tosave);
              }catch(Exception e){System.out.println(e);}
    i think u get me
    regards
    [email protected]

Maybe you are looking for

  • Panic Kernel problem on older Imac

    Hi Folks, I have recently, (the last week) been getting kernal panic messages everytime my system is run. I have 10.7.5 running on a early or mid 2009 Imac 24. As far as I recall, we have not updated anything or added anything in the last week to cau

  • I-Tunes Transfer Script - Duncan Bernhardt

    I'm not sure if this is the correct location for this, but i noticed that some other site admins are getting help directly from Duncan Bernhardt, so i'll give it a go. I'm trying to do the initial setup for our I-tunes account (the address is https:/

  • Mac OS X Yosemite Reboot Loop

    Hey guys, I just upgraded to Yosemite a couple of days ago and it was working fine. Now,while using it the OS suddenly crashed and now I can't turn it on - it makes the startup chime and the apple logo appears alogn with the bar. However, when the ba

  • Hiding option in ALV

    Hi , Is there any option to hide columns in ALV?

  • Upgrade PS CS5 to CS6 for MAC

    The link to buy CS6 upgrade from CS5 does work, but it only yields a Windows version. The "Windows" is greyed out and cannot be changed in the shopping cart. Any work around for a MAC user?