File Upload.. Strange Problem..

im trying to read file data and print it in the browser. I dont want to save the file. just to read the uploaded file which is TAB delimited..
First time it works fine. but If I browse back button and reload another file and submit. I am getting content of first file and second file. I closed the browser and reopened it but still problem is not resolved. it keeps on adding file content instead of showing current uploaded file. I dont know what to do.
here is my code
upload.html
<html>
<head>
<title>File Upload Form</title>
</head>
<body>
Upload File using this..
<FORM METHOD="POST" ENCTYPE="multipart/form-data" action="uploadFile.jsp">
File: <input type="file" name="file"><br>
<input value="Submit" type="submit">
</form>
</body>
</html>
UploadFile.jsp
=============
<%@page language="java" import="java.io.*" %>
<%@page language="java" import="java.util.*" %>
<%!
private BufferedInputStream bis = null;
int MAX_LINES = 2000;
private String currentLine = "";
//private String[] PartNumber;
//private String[] Quantity;
public int disp_counter = 0;
public int mime_counter = 0;
public int boundary_counter = 0;
private String content_diposition = null;
private HttpServletRequest request;
private javax.servlet.jsp.JspWriter mOut;
The incoming request needs to be an InputStream before it can be parsed. This method creates an InputStream from the request. The
request contains the uploaded file contents
public void setInputStream(HttpServletRequest request, JspWriter _out)throws IOException {
try{
bis = new BufferedInputStream(request.getInputStream());
} catch(IOException e){
e.printStackTrace();
this.request = request;
this.mOut = _out;
//mOut.println("After setting input Stream<br>");
private int getRealContentLength() throws Exception
boundary_counter = readBoundaryLength(bis);
content_diposition = readContentDisposition(bis);
//mOut.println(" getRealContentLength() content_diposition ="+content_diposition+"<br>");
mime_counter = readUntilBody(bis);
int tmpContentLength = getContentLength();
int retLength;
mOut.println(" getRealContentLength() boundary_counter ="+boundary_counter+"<br>");
mOut.println(" getRealContentLength() content_diposition ="+content_diposition+"<br>");
mOut.println(" getRealContentLength() disp_counter ="+disp_counter+"<br>");
mOut.println(" getRealContentLength() mime_counter ="+mime_counter+"<br>");
mOut.println(" getRealContentLength() tmpContentLength ="+tmpContentLength+"<br>");
retLength = getContentLength()-boundary_counter-2-mime_counter-disp_counter;
return retLength;
private int readBoundaryLength(BufferedInputStream fis) throws Exception{
//mOut.println("---- Inside readBoundaryLength ----<br>");
StringBuffer sb = new StringBuffer();
byte[] b = new byte[1];
int counter=0;
while(true){
try{
fis.read(b);
counter++;
//mOut.println("RB "+counter+"="+b[0]+"<br>");
sb.append( new String(b));
//if('\r'==b[0])
if(13==b[0]){
fis.read(b);
sb.append( new String(b));
//mOut.println("RB next="+b[0]+"<br>");
break;
}catch(IOException e){
e.printStackTrace();
//mOut.println("----Counter before return="+counter+" STR="+sb.toString()+"----<br>");
b = null;
//mOut.println("---- End readBoundaryLength ----<br>");
return counter+1;
private int readUntilBody(BufferedInputStream fis) throws Exception{
byte[] b = new byte[1];
mime_counter=0;
int counter = 0;
StringBuffer sb = new StringBuffer();
while(true){
try{
fis.read(b);
sb.append(new String(b));
mime_counter++;
//mOut.println("RUntilB "+mime_counter+"="+b[0]+"<br>");
//if('\r'==b[0])
if(13==b[0])
counter++;
if(counter == 2){
fis.read(b);
sb.append(new String(b));
//mOut.println("RUntilB counter=2 "+mime_counter+"="+b[0]+"<br>");
break;
}catch(IOException e){
e.printStackTrace();
b = null;
//mOut.println("RUntilB="+sb.toString()+"<br>");
return mime_counter;
private int getContentLength(){
return request.getContentLength();
private String readContentDisposition(BufferedInputStream fis) throws Exception{
byte[] b = new byte[1];
disp_counter=0;
StringBuffer sb = new StringBuffer();
while(true){
try{
fis.read(b);
disp_counter++;
sb.append(new String(b));
//mOut.println("ReadCD "+disp_counter+"="+b[0]+"<br>");
//if('\r'==b[0])
if(13==b[0]){
for(int i=1; i < 2; i++){
sb.append(new String(b));
fis.read(b);
//mOut.println("ReadCD before break="+b[0]+"<br>");
break;
}catch(IOException e){
e.printStackTrace();
//mOut.println("----disp_counter before return="+disp_counter+" STR="+sb.toString()+"----<br>");
b=null;
disp_counter += 1;
return sb.toString();
private String readNumberOfBytes(BufferedInputStream bis, int count) throws Exception{
byte[] b = new byte[count];
byte[] tmp = new byte[count];
int offset = 0;
int icount = count;
int i=0;
String tmpStr = null;
try{
while((i = bis.read(b,0,icount)) != -1){
System.arraycopy(b,0,tmp,offset,i);
tmpStr = new String( tmp );
//mOut.println( "*****"+tmpStr );
if(icount - i > 0) {
icount = count - i;
offset +=i;
continue;
else
break;
}catch(IOException e){
e.printStackTrace();
//for (i=0; i<b.length; i++)
// mOut.println("AC"+i+"="+b+"<br>");
return tmpStr;
public String parseFile( ) throws Exception {
int len = readAll(bis);
mOut.println("total len="+len+"<br>");
//in the first phase, throw away the request parameters that are not required
//in the second phase, grab the required stuff
int reallength;
int mod = 0;
int div = 0;
//get rid of the unwanted request content
reallength = getRealContentLength();//this is the orig line
//mOut.println( "reallength is " + reallength +"<br>");
//get rid of boundary and content disp header.
//int bound_len = readBoundaryLength(bis);
//String content_disp = readContentDisposition(bis);
//mOut.println( "Xbound_len" + bound_len +"<br>");
//mOut.println( "xcontent_disp" + content_disp +"<br>");
//now we are at partnos,qty
//int body = readUntilBody(bis);
if(reallength < 2048){
currentLine += readNumberOfBytes(bis,reallength);
else{
div = reallength / 2048;//buffer default size
mod = reallength % 2048;
mOut.println("div ="+div+" mod="+mod+"<br>");
for(int i=0; i < div; i++)
currentLine += readNumberOfBytes(bis,2048);
if(mod != 0)
currentLine += readNumberOfBytes(bis,mod);
//mOut.println( "currentLine" + currentLine );
//ExtractPartNumberAndQuantity();
//mOut.println("total length="+currentLine.length()+"<br>");
int lastInd = currentLine.lastIndexOf('\r');
//mOut.println("lastInd="+lastInd+"<br>");
lastInd = currentLine.lastIndexOf('\r',lastInd-1);
//mOut.println("lastInd="+lastInd+"<br>");
currentLine= currentLine.substring(0,lastInd);
//mOut.println( "currentLine="+currentLine+"<br>" );
return currentLine;
%>
<%
out.println(" request length="+request.getContentLength()+"<br>");
setInputStream(request,out);
String allLines = parseFile();
out.println("************** Parsing string starts <br>");
StringBuffer sb = new StringBuffer();
sb.append( (char)13 );
sb.append( (char)10 );
StringTokenizer st = new StringTokenizer( allLines,sb.toString());
String line = null;
// skip the first line as this is header...
if( st.hasMoreTokens() )
line = st.nextToken();
while( st.hasMoreTokens() )
line = st.nextToken();
out.println(line+"<br>");
out.flush();
%>

err..
<%!
private BufferedInputStream bis = null;
int MAX_LINES = 2000;
private String currentLine = "";
//private String[] PartNumber;
//private String[] Quantity;
public int disp_counter = 0;
public int mime_counter = 0;
public int boundary_counter = 0;
private String content_diposition = null;
private HttpServletRequest request;
private javax.servlet.jsp.JspWriter mOut;
that's the problem, most likely.... the <%! part to hold all the variables. Particularly coudl've been a problem if you have multple requests at the same time..

Similar Messages

  • File Upload element Problem

    Hello All,
    We have a problem regarding the File Upload button in Webdynpro.
    when we upload a file using this element and goto another view and comeback, the upload element is not showing any filename.
    But when debugged, the fileupload context node still has the data. Just it is not showing in the UI.
    Is it an existing problem with File Upload? Or do we have to do anything to make the filename visible.
    Thanks,
    Anand

    Hi,
    this works as designed, see the section on browser details <a href="http://help.sap.com/saphelp_nw70/helpdata/en/b3/be7941601b1d09e10000000a155106/frameset.htm">here</a>
    Regards, Heidi

  • File Upload demo problem

    Hi!, i have a problem with the File Upload Demo when it calls this line:
    hDirectoryObject := JFile.new(directory);
    and the error is: error 6508 "PL/SQL: could not find program unit being called"
    That's ok, but anybody knows why should the program couldnt find the routine ?
    And just one more thing...where can i look for JFile method description ??
    Thanks a lot :) !!
    Cristian.

    Is this 9i or 6i?
    JFile is an imported wrapper for a Java Class - it should be in the Demo form already - you could try a compile all on the file just in case.

  • File Upload / ENCTYPE Problem - Please HELP !!!!!!

    Please HELP !!!
    I have following config. MS Windows Server 2003 with
    Coldfusion 7. Everything is working fine.
    But now I want to upload a file, and there is the problem
    that I have the wrong content type on my action page, and so my
    form field "FileContents" is empty.
    On my action page i have got content_type
    "application/x-www-form-urlencoded" instead of
    "multipart/form-data".
    Here is the code:
    --------------------uploadfileform.cfm--------------------
    <cfoutput>
    <form enctype="multipart/form-data" method="post"
    action="uploadfileaction.cfm" name="uploadForm" id="uploadForm">
    <input name="FileContents" type="file"
    id="FileContents">
    <br>
    <input name="submit" type="submit" value="Upload File">
    </form>
    </cfoutput>
    --------------------uploadfileaction.cfm--------------------
    <cffile action="upload" fileField="FileContents"
    destination="e:\tempdir" nameConflict="MakeUnique">
    If there is anyone who can help me please be so kind and tell
    me the solution.
    Kind Regards!

    On my action page i have got content_type
    "application/x-www-form-urlencoded" instead of
    "multipart/form-data".
    There is no need for that sort of thing on the action page.
    On the action page the cffile tag is enough.
    Everything else seems to be all right, except one. The
    destination attribute should end with a back-slash. The correct
    value is
    destination="e:\tempdir\".

  • File Upload -- MultipartRequest Problem

    I use com.oreilly.servlet.MultipartRequest to upload files through a servlet.
    This works fine, but when the size of a file exceeds the maximum size,
    I need to handle the IOException but it doesn't work.
    here is the code:
    try {
    if (file != null) {
    File outputFile = new File(fullPath,fileName);
    FileInputStream inFile = new FileInputStream(file);
    FileOutputStream outFile = new FileOutputStream(outputFile);
    while (inFile.available()>0) {
    outFile.write(inFile.read());
    inFile.close();
    outFile.close();
    return (fileName);
    catch( java.io.IOException e ) {
    System.out.println("DiskFileUpload write failed" + e.toString());
    return (null);
    catch ( java.lang.Exception le) {
    System.out.println("DiskFileUpload write failed" + le.toString());
    response.sendRedirect("error.html");

    What is the problem you are getting?
    Are you getting Page Cannot displayed Browser page?

  • (JSP/SERVLET) File upload Character problem form enctype="multipart.....

    Hi,
    When i upload a file from <form> ( jsp page ) and send it to my object class(struts,servlet) , the filename �����.doc are replaced by ?????.doc. in the database.
    I make few test by adding UTF-8 charset and content type to the jsp but still doesn't work...
    Ex :
    String encod = request.getCharacterEncoding();
    if (encod == null || !encod.equals("UTF-8"))
    try
    request.setCharacterEncoding("UTF-8");
    catch (UnsupportedEncodingException e)
    System.err.println("HttpMultipartRequest - : " + e);
    It's not a charset problem in the database because i try to do with an input type="text" and its working. It's just not working with the input type="file".
    And i also add directly ��� character into the database and its working.
    it's will be a pleasure if someone could response to me .
    thanks
    Jonathan

    warnerja,
    Not sure why you always play the part of the
    cross-post police... Seems like waste of effort to
    me.To each his own. I'm not sure why you feel the need
    to question my motives. Also not sure why you have
    posted requests to Sun regarding forum features...
    "Seems like a waste of effort to me.". But I wasn't
    going to call you on it.touch�
    :-)

  • File Upload/Download Problem

    Hi,
    I have a fileupload button. The attributes type is XSTRING, which i bound it with "data" property of download.
    When i download this file with "download" element, it comes in a zip file and as XML files. Only the jpg files are downloaded correctly.
    How can i solve this?
    Thanks.

    Hi,
    I am so sory for my very late answer.
    If you want to upload/download files, you should have a node which includes attributes
    (attribute names are just example ):
    1) filename(type: for example afilename),
    2)mimetype (type : string),
    3) file(type : a data element with type 'RAWSTRING').
    You must match your fileupload element's attributes with them:
    "DATA" attribute --> file ,
    "fileNAME" attribute--> filename,
    "mimeTYPE" attritube -->mimetype.
    When you want to download this file, you should put a filedownload element and match this element's attributes with the node's attributes which i described above.

  • File Upload Concept Problem

    Hi, I am writing a WAS4 webapp which will allow users to upload files to the WAS machine. I've written and deployed apps on WAS4 before and I create a war file and deploy it via the admin console. But something I don't quite understand is that if I create a folder, say 'upload' underneath my context root such that the path is /contextRoot/upload and this folder is inside the war file, can a user upload into this folder?
    If not, then where must I place the folder in order to perform uploads and how can I reference this folder from my java code? Do I give it absolute machine paths, or some other sort of context relative path?

    Did you try using Jakarta FileUpload? It will answer all your questions.
    http://jakarta.apache.org/commons/fileupload/using.html

  • File upload component problem

    hi,
    When i use fileupload component in my page, Turkish characters is not renderind and i see them as question mark. Changing page encoding is not working and solving my problem, too.
    any suggestion would be appreciated.
    Regards...

    I got exact the same problem, but with Chinese characters display. Does that means we can only use upload with English characters? Any solutions in the future?
    Thanks,

  • FILE UPLOAD PROBLEM SHOWING THE CONTENTS IN THE SAME BROWSER WINDOW

    Hi,
    This is amit Joshi
    I have uploaded content using input tag of type file and posted to jsp as multipart/form-data type
    in that jsp i am using following code to display the content in browser but only first content is displayed How can i modify it to show all content in the file ..
    <html>
    <head>
    <title>File Upload Display</title>
    </head>
    <body>
    <%
    //ServletOutputStream sout=response.getOutputStream();
    StringBuilder strBuilder = new StringBuilder();
    int count=0;
    String f;
    f=request.getParameter("filedb");
    DBManager dbm = new DBManager();
    //dbm.createTable("mms3");
    //log.info("In JSP : "+ f);
    //dbm.insert_data(f,"mms3");
    %>
    <%
    if (ServletFileUpload.isMultipartContent(request)){
    ServletFileUpload servletFileUpload = new ServletFileUpload(new DiskFileItemFactory());
    List fileItemsList = servletFileUpload.parseRequest(request);
    strBuilder.append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>").append('\r').append('\n').append("<xpage version=\"1.0\">").append('\r').append('\n');
    String optionalFileName = "";
    FileItem fileItem = null;
    Iterator it = fileItemsList.iterator();
    ServletOutputStream outputStream=null;
    while (it.hasNext()){
    FileItem fileItemTemp = (FileItem)it.next();
    if (fileItemTemp.isFormField()){
    %>
    <b>Name-value Pair Info:</b>
    Field name: <%= fileItemTemp.getFieldName() %>
    Field value: <%= fileItemTemp.getString() %>
    <%
    if (fileItemTemp.getFieldName().equals("filename"))
    optionalFileName = fileItemTemp.getString();
    else
    fileItem = fileItemTemp;
    if (fileItem!=null){
    String fileName = fileItem.getName();
    %>
    <b>Uploaded File Info:</b>
    Content type: <%= fileItem.getContentType() %>
    Field name: <%= fileItem.getFieldName() %>
    File name: <%= fileName %>
    <%
    if(fileItem.getContentType().equals("image/jpeg")) { %>
    File : <p><%
         //response.setContentType("image/gif");
         byte[] bArray=fileItem.get();
         response.setContentType("image/jpeg");
         outputStream=null;
         outputStream= response.getOutputStream();
         outputStream.write(bArray);
         outputStream.flush();
         outputStream.close();
    else if(fileItem.getContentType().equals("text/plain"))
         %> File : <%= fileItem.getString() %>
    <%
    byte[] bArray=fileItem.get();
    response.setContentType("text/plain");
         outputStream = response.getOutputStream();
         out.println();
         outputStream.write(bArray);
         outputStream.flush();
         outputStream.close();
    %> </p> <%
    %>
    </body>
    </html>
    Edited by: Amit_Joshi on Nov 13, 2007 10:58 PM

    Well Well Well..
    That would not work...
    What you have to do is save the uploaded file content on to a location and then pass the fileName as a request parameter to a deidicated which displays the contents of that file.
    Just as an example
    <html>
    <head>
    <title>File Upload Display</title>
    </head>
    <body>
    <%
    //ServletOutputStream sout=response.getOutputStream();
    StringBuilder strBuilder = new StringBuilder();
    int count=0;
    String f;
    f=request.getParameter("filedb");
    DBManager dbm = new DBManager();
    //dbm.createTable("mms3");
    //log.info("In JSP : "+ f);
    //dbm.insert_data(f,"mms3");
    %>
    <%
    if (ServletFileUpload.isMultipartContent(request)){
    ServletFileUpload servletFileUpload = new ServletFileUpload(new DiskFileItemFactory());
    List fileItemsList = servletFileUpload.parseRequest(request);
    strBuilder.append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>").append('\r').append('\n').append("<xpage version=\"1.0\">").append('\r').append('\n');
    String optionalFileName = "";
    FileItem fileItem = null;
    Iterator it = fileItemsList.iterator();
    ServletOutputStream outputStream=null;
    while (it.hasNext()){
       FileItem fileItemTemp = (FileItem)it.next();
    %>
    Name-value Pair Info:
    Field name: <%= fileItemTemp.getFieldName() %><br/>
    Field value: <%= fileItemTemp.getString() %><br/>
    <%
    if (fileItemTemp.getFieldName().equals("filename"))
        optionalFileName = fileItemTemp.getString();
    if(!fileTempItem.isFormFiled()){
       String fileName = fileItem.getName();
       fileItem.write(optionalFileName);
    %>
    Uploaded File Info:
    Content type: <%= fileItem.getContentType() %><br/>
    Field name: <%= fileItem.getFieldName() %><br/>
    File name: <%= fileName %><br/>
    <%
    if(fileItem.getContentType().equals("image/jpeg") || fileItem.getContentType().equals("image/pjeg")) {
    %>
      <img src="FileServlet?fileName=<%=optionalFileName%>"   
    <%
    %>
    </body>
    </html>a sample code snippet for FileServlet.
    String fileName =  request.getParameter(fileName);
      File file = new File(fileName);
       if(!file.exists())
         return;
      // If JSP
      String mimeType = application.getMimeType("fileName");
           If you are using servlet
           String mimeType = this.getServletContext().getMimeType(fileName);
         response.setContentType(mimeType);  
         response.setHeader("Content-Disposition","inline;filename=\\"+fileName+"\\");
      BufferedOutputStream out1 = null;
      InputStream in = null;
      if(mimeType == null)
         mimeType = "application/octet-stream";
      try{
         in = new FileInputStream(f);
         response.setContentLength(in.available());
         BufferedOutputStream out1 = new BufferedOutputStream(response.getOutputStream(),1024);
         int size = 0;
         byte[] b = new byte[1024];
         while ((size = in.read(b, 0, 1024)) > 0)
            out1.write(b, 0, size);
      }catch(Exception exp){
      }finally{
          if(out1 != null){
             try{
                out1.flush();               
                out1.close();
             }catch(Exception e){}
          if(in != null){
            try{in.close();}catch(Exception e){}
      } Hope that might answer your question :)
    However,this is not the recommended way of doing this make use of MVC pattern.Would be a better approach.
    you might think of googling on this and can findout what is the best practise followed for problems of this sort
    REGARDS,
    RaHuL

  • Threading problem during File Upload with Apache faces upload tag

    First I am going to tell you "My Understanding of how JSF Apache Upload works, Correct me if i am wrong".
    1) Restores View (to show Input box and Browse button to facilitate users to select a file for upload)
    2) Translates Request Parameters to Component Values (Creates equivalent components to update them with request values).
    3) Validates Input(Checks to see whether the User has input the correct file)
    4) Updates Backing Bean or Model to reflect the values.
    5) Renders response to user.
    I am uploading huge files of sizes 400MB and above with the help of JSF apache extensions tag
    <h:form id="uploadForm" enctype="multipart/form-data">
    <x:inputFileUpload style="height:20px;" id="upload" value="#{backingbean.fileContents}" storage="file" size="50" />
    </h:form>
    In the backing bean
    private UploadedFile fileContents;
         public UploadedFile getFileContents() {
              return fileContents;
         public void setFileContents(UploadedFile fileContents) {
              System.out.println("File being uploaded...");
              this.fileContents = fileContents;
    Since, the file size is so huge, I am using temp folder to use for the apache tag instead of memory.
    In web.xml i am using like this
    <filter>
    <filter-name>ExtensionsFilter</filter-name>
    <filter-class>org.apache.myfaces.component.html.util.ExtensionsFilter</filter-class>
    <init-param>
    <param-name>uploadMaxFileSize</param-name>
    <param-value>600m</param-value>
    </init-param>
    <init-param>
    <param-name>uploadThresholdSize</param-name>
    <param-value>10m</param-value>
    </init-param>
         <init-param>
    <param-name>uploadRepositoryPath</param-name>
    <param-value>/uploadfolder/</param-value>
    </init-param>
    </filter>
    <filter-mapping>
    <filter-name>ExtensionsFilter</filter-name>
    <servlet-name>Faces Servlet</servlet-name>
    </filter-mapping>
    The upload process is working perfectly fine.
    Now coming to the problem:
    Suppose one user is logging into the application & uploading say 400MB of files.
    Until these files are linked to the model objects as my understanding of step 2, if second user tries to open the application he gets stuck with the loading page.
    The page gets loaded only after the request files are linked to the component values(Step 2 above) and updates the backing bean's values.
    I don't see any error in the logs. User is getting stuck. The user is getting stuck only when uploading the files. The other operations like searching are not blocking any other activities performed by the user.
    Server used: IBM Application Server V6.0. CPU is normal, memory usage is normal.

    Dear friend,
    i am also trying to upload using the common file upload.
    when try to run the file error is coming
    can give some suggestion.
    can i use if concurrent user file upload at a time

  • Problem with File Uploading.

    Hi,
    I have one problem with File Upload component.
    JSP
    <ui:upload binding="#{NewProblem.fileUpload1}" columns="#{SessionBean1.uploadedFile}" id="fileUpload1" labelLevel="3"
    style="left: 24px; top: 24px; position: absolute" validator="#{NewProblem.fileUpload1_validate}"/>
    Java
    UploadedFile uploadedFile = getSessionBean1().getUploadedFile();
    Variable uploadedFile is NULL :(((((((((((
    web.xml
    <context-param>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>client</param-value>
    </context-param>
    <filter>
    <filter-name>UploadFilter</filter-name>
    <filter-class>com.sun.web.ui.util.UploadFilter</filter-class>
    <init-param>
    <param-name>maxSize</param-name>
    <param-value>10000000</param-value>
    </init-param>
    <init-param>
    <param-name>sizeThreshold</param-name>
    <param-value>10024</param-value>
    </init-param>
    </filter>
    Thanks.

    check out the fileUpload article
    Using the File Upload Component
    http://developers.sun.com/prodtech/javatools/jscreator/learning/tutorials/2/file_upload.html

  • Problem with Multi File upload example, help needed

    I got the code from the following location.....
    http://www.adobe.com/devnet/coldfusion/articles/multifile_upload.html
    And I've got it to work to some degree except I cant get the file transfer to work when pressing, Upload.   Below is what my debugger outputs.  Any thoughts on how to fix this or even what it means?
    At the very bottom of this message is the upload.cfm code.......
    Thanks in advance for the help
    <html>
    <head>
      <title>Products - Error</title>
    </head>
    <body>
    <h2>Sorry</h2>
    <p>An error occurred when you requested this page.
    Please email the Webmaster to report this error.
    We will work to correct the problem and apologize
    for the inconvenience.</p>
    <table border=1>
    <tr><td><b>Error Information</b> <br>
      Date and time: 12/07/09 22:25:51 <br>
      Page:  <br>
      Remote Address: 67.170.79.241 <br>
      HTTP Referer: <br>
      Details: ColdFusion cannot determine how to process the tag &lt;CFDOCUMENT&gt;. The tag name may be misspelled.<p>If you are using tags whose names begin with CF but are not ColdFusion tags you should contact Allaire Support. <p>The error occurred while processing an element with a general identifier of (CFDOCUMENT), occupying document position (41:4) to (41:70).<p>The specific sequence of files included or processed is:<code><br><strong>D:\hshome\edejham7\edeweb.com\MultiFileUpload\upload.cfm      </strong></code><br>
      <br>
    </td></tr></table>
    </body>
    </html>
    <!---
    Flex Multi-File Upload Server Side File Handler
    This file is where the upload action from the Flex Multi-File Upload UI points.
    This is the handler the server side half of the upload process.
    --->
    <cftry>
    <!---
    Because flash uploads all files with a binary mime type ("application/ocet-stream") we cannot set cffile to accept specfic mime types.
    The workaround is to check the file type after it arrives on the server and if it is non desireable delete it.
    --->
        <cffile action="upload"
                filefield="filedata"
                destination="#ExpandPath('\')#MultiFileUpload\uploadedfiles\"
                nameconflict="makeunique"
                accept="application/octet-stream"/>
            <!--- Begin checking the file extension of uploaded files --->
            <cfset acceptedFileExtensions = "jpg,jpeg,gif,png,pdf,flv,txt,doc,rtf"/>
            <cfset filecheck = listFindNoCase(acceptedFileExtensions,File.ServerFileExt)/>
    <!---
    If the variable filecheck equals false delete the uploaded file immediatley as it does not match the desired file types
    --->
            <cfif filecheck eq false>
                <cffile action="delete" file="#ExpandPath('\')#MultiFileUpload\uploadedfiles\#File.ServerFile#"/>
            </cfif>
    <!---
    Should any error occur output a pdf with all the details.
    It is difficult to debug an error from this file because no debug information is
    diplayed on page as its called from within the Flash UI.  If your files are not uploading check
    to see if an errordebug.pdf has been generated.
    --->
            <cfcatch type="any">
                <cfdocument format="PDF" overwrite="yes" filename="errordebug.pdf">
                    <cfdump var="#cfcatch#"/>
                </cfdocument>
            </cfcatch>
    </cftry>

    Just 2 things in my test:
    1) I use no accept attribute. Coldfusion is then free to upload any extenstion.
    Restricting the type to application/octet-stream may generate errors. Also, it is unnecessary, because we perform a type check anyway.
    2) I have used #ExpandPath('.')#\ in place of #ExpandPath('\')#
    <cfif isdefined("form.filedata")>
    <cftry>
    <cffile action="upload"
                filefield="filedata"
                destination="#expandPath('.')#\MultiFileUpload\uploadedfiles\"
                nameconflict="makeunique">
            <!--- Begin checking the file extension of uploaded files --->
            <cfset acceptedFileExtensions = "jpg,jpeg,gif,png,pdf,flv,txt,doc,rtf"/>
            <cfset filecheck = listFindNoCase(acceptedFileExtensions,File.ServerFileExt)/>
    <!---
    If the variable filecheck equals false delete the uploaded file immediatley as it does not match the desired file types
    --->
            <cfif filecheck eq false>
                <cffile action="delete" file="#ExpandPath('.')#\MultiFileUpload\uploadedfiles\#File.ServerFile#"/>
                <cfoutput>Uploaded file deleted -- unacceptable extension (#ucase(File.ServerFileExt)#)</cfoutput>.<br>
            </cfif>
    Upload process done!
            <cfcatch type="any">
                There was an error!
                <cfdocument format="PDF" overwrite="yes" filename="errordebug.pdf">
                    <cfdump var="#cfcatch#"/>
                </cfdocument>
            </cfcatch>
    </cftry>
    <cfelse>
    <form method="post" action=<cfoutput>#cgi.script_name#</cfoutput>
            name="uploadForm" enctype="multipart/form-data">
            <input name="filedata" type="file">
            <br>
            <input name="submit" type="submit" value="Upload File">
        </form>
    </cfif>

  • File Upload problem: JSF, IBM WPS and Portlet - Please HELP Vey Very Urgent

    I want to upload a file from the front end using JSF and Portlets deployed on IBM WebSphere Portal.
    I have used Apache's commons file upload functionality as the file upload provided in JSF doesnot work with portlets and the action event is not invoked If I keep enctype="multipart/form-data". So I included 3 forms in my Faces JSP file.
    1) h:form = For displyign error message on screen
    2) html:form = Include the enctype="multipart/form-data" and the input type file for uploading. And a submit button
    3) h:form: Here I have a command link which is remotely excuted on click of sumit button in my html form. This is to invoke the action event in the pagecode to get the bean value from the context.
    Now in the my doView method in the portlet, isMultipartContent(httpservletrequest) always returns null as the content type is text/html and not multipart. Onclick of the submit button in the the html form I am calling a javascript function which sets the __LINK_TARGET__ to the command link in the 3rd h:form which will call the page code.
    The problem here is action is invoked only when I return false from the above javascript else it will trigger for the first time and from second time onwards it will not invoke the action event in the pagecode method. Whent the javascript function returns false, the content type is always text/html. However if I return "true" from the javascript the content type is multipart/form-data, but the action is not triggered for the second time. So basically when the javascript functions returns true, for the first click everything works perfectly. When it returns false, the content type is text/html, but the action is invoked in the page code every time.
    Returning always true would solve my problem with the content type, but the action with the command link will not get invoked always as its some type of problem with h:commanLink :(.
    I guess I gave too much info. Heres my code stepby step.
    Can somebody please tell me , how I should also invoke the action in the page code and get the content type as "multipart/form-data" at the same time.
    1:
    ======================= Faces JSP File: BPSMacro.jsp ====================
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <meta name="GENERATOR" content="IBM Software Development Platform">
    <meta http-equiv="Content-Style-Type" content="text/css">
    <%@taglib uri="http://java.sun.com/portlet" prefix="portlet"%>
    <%@taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
    <%@taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt"%>
    <%@taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
    <%@taglib uri="http://www.ibm.com/jsf/html_extended" prefix="hx"%>
    <%@taglib uri="/WEB-INF/tld/j4j.tld" prefix="j4j"%>
    <%@taglib uri="/WEB-INF/tld/core.tld" prefix="core"%>
    <%@page language="java" contentType="text/html; charset=ISO-8859-1"
         pageEncoding="ISO-8859-1" session="false"%>
    <portlet:defineObjects />
    <link rel="stylesheet" type="text/css"
         href='<%= renderResponse.encodeURL(renderRequest.getContextPath() + "/theme/stylesheet.css") %>'
         title="Style">
    <script type="text/javascript">
    function formSubmit() {
         var formName2 = document.getElementById("proxy_form_main_").title;
         var formName1 = document.getElementById("BPSMacroFormId").title;
         document.getElementById("__LINK_TARGET__").value = document.getElementById("proxy_HD_COMMAND_").title;
         document.getElementById(formName2).submit();
         return false;
    </script>
    <f:view>
         <hx:scriptCollector id="bpsMacroScriptCollector">
              <f:loadBundle var="bps" basename="bordereauprocessingsystem" />
              <table bgcolor="#FFF9C3">
                   <tr>
                        <td><h:form id="BPSMacroFormMain" styleClass="form">
                             <table class="tablemiddle" cellspacing="0" cellpadding="0">
                                  <tr>
                                       <td><h:messages layout="table" styleClass="errormessage"
                                                 id="ValidationErrorMsg" /> </td>
                                  </tr>
                             </table>
                             <j4j:idProxy id="proxy_form_main_0_" />
                        </h:form></td>
                   </tr>
                   <tr>
                        <td>
                        <form id="BPSMacroFormId" enctype="multipart/form-data">
                        <table bgcolor="#FFF9C3">
                             <tr>
                                  <td height="36" width="324">Worksheet <input type="file"
                                       name="upfile" /></td>
                             </tr>
                                  <tr>
                                       <td align="center" width="324"><input TYPE="submit"
                                       onclick="return formSubmit();" value="Upload">
                                  </td>
                             </tr>
                        </table>
                        </form>
                        </td>
                   </tr>
                   <tr>
                        <td>
                        <h:form id="BPSMacroFormMain2" styleClass="form">
                             <table cellspacing="2" cellpadding="2" class="tablemiddle">
                                  <tbody>
                                       <tr>
                                            <td colspan="2" align="center"><h:commandLink
                                                 styleClass="commandLink" id="lnkuserdelete"
                                                 action="#{pc_BPSMacro.doIdUpload1Action}">
                                                 <hx:graphicImageEx
                                                      styleClass="graphicImageEx" id="imgBtnCreateUser"
                                                      value="/theme/images/btnUpload.gif" style="border:0;cursor:pointer"></hx:graphicImageEx>
                                                 <j4j:idProxy id="proxy_HD_COMMAND_" />
                                            </h:commandLink></td>
                                            <h:inputHidden id="dtSize"
                                                 value="#{pc_BPSMacro.fileDetailsList.clicked}">
                                                 <j4j:idProxy id="proxy_clicked_" />
                                            </h:inputHidden>
                                       </tr>
                                  </tbody>
                             </table>
                             <j4j:idProxy id="proxy_form_main_" />
                        </h:form>
                   </td>
                   </tr>
              </table>
         </hx:scriptCollector>
    </f:view>
    ================== END: FACES JSP FILE: BPSMacro.jsp ========================
    2:
    =================== Action event in the Page Code: BPSMacro.java ============
    public String doIdUpload1Action() {
              System.out.println("PageCode");
              FacesContext context = FacesContext.getCurrentInstance();
              BPSMacroDetailsDataBean fileDetails = (BPSMacroDetailsDataBean)context.getApplication().createValueBinding("#{fileDetails}").getValue(context);
              BPSMacroListDataBean fileDetailsList = (BPSMacroListDataBean)context.getApplication().createValueBinding("#{fileDetailsList}").getValue(context);
              PortletSession sess = (PortletSession)context.getExternalContext().getSession(false);
              sess.setAttribute("BPS_MACRO_CONTEXT", context, PortletSession.APPLICATION_SCOPE);
              sess.setAttribute("BPS_MACRO_FILE_DETAILS", fileDetails, PortletSession.APPLICATION_SCOPE);
              sess.setAttribute("BPS_MACRO_FILE_LIST", fileDetailsList, PortletSession.APPLICATION_SCOPE);
              HttpServletRequest request = (HttpServletRequest)context.getExternalContext().getRequest();
              boolean isMultipart = ServletFileUpload.isMultipartContent(request);
              request.getContentType();
              return "gotoBPSMacro";
    ============== END Of Page Code Action event ==============================
    3:
    ============== doView() Portlet method ================================
    public void doView(RenderRequest arg0, RenderResponse arg1)
         throws PortletException, IOException {
              String METHOD_NAME = "doView(RenderRequest arg0, RenderResponse arg1)";
              Logger.debug(this.getClass(), METHOD_NAME, "Entering BPSMacroPortlet");
              FacesContext context = FacesContext.getCurrentInstance();      
              PortletSession sess1 = arg0.getPortletSession(true);
              BPSMacroDetailsDataBean fileDetails = new BPSMacroDetailsDataBean();
              BPSMacroListDataBean fileDetailsList = new BPSMacroListDataBean();
              context = (FacesContext)sess1.getAttribute("BPS_MACRO_CONTEXT", PortletSession.APPLICATION_SCOPE);
              if(context != null){
                   fileDetails = (BPSMacroDetailsDataBean)sess1.getAttribute("BPS_MACRO_FILE_DETAILS", PortletSession.APPLICATION_SCOPE);
                   fileDetailsList = (BPSMacroListDataBean)sess1.getAttribute("BPS_MACRO_FILE_LIST", PortletSession.APPLICATION_SCOPE);
              sess1.removeAttribute("BPS_MACRO_CONTEXT", PortletSession.APPLICATION_SCOPE);
              sess1.removeAttribute("BPS_MACRO_FILE_DETAILS", PortletSession.APPLICATION_SCOPE);
              sess1.removeAttribute("BPS_MACRO_FILE_LIST", PortletSession.APPLICATION_SCOPE);
              HttpServletRequest servletRequest = (HttpServletRequest)arg0;
              PortletRequest pReq = (PortletRequest)arg0;
              HttpServletResponse servletResponse= (HttpServletResponse)arg1;
              System.out.println("\n\n Content Type" + servletRequest.getContentType());
              try{
                   if(context != null){
              boolean isFileMultipart = ServletFileUpload.isMultipartContent(servletRequest);
              System.out.println("\nFILE TO BE UPLOADED IS MULTIPART ? " + isFileMultipart);
              if(isFileMultipart){
                   FileItemFactory factory = new DiskFileItemFactory();
                   ServletFileUpload upload = new ServletFileUpload(factory);
                   List items = upload.parseRequest(servletRequest);
                   Iterator iterator = items.iterator();
                   while (iterator.hasNext()) {
                        FileItem item = (FileItem) iterator.next();
                        InputStream iStream = item.getInputStream();
                        ByteArrayOutputStream ByteArrayOS = new ByteArrayOutputStream();
                        int sizeofFile =(int) item.getSize();
                        byte buffer[] = new byte[sizeofFile];
                        int bytesRead = 0;
                        while( (bytesRead = iStream.read(buffer, 0, sizeofFile)) != -1 )
                             ByteArrayOS.write( buffer, 0, bytesRead );
                        String data = new String( ByteArrayOS.toByteArray() );
                        int k = 0;
                        //Check if the file is Refund or Premium
                        int dynamicArraySize = 0;// = st2.countTokens() * 9;
                        dynamicArraySize = st2.countTokens() * 9;
                        if (!item.isFormField() ){
                             File cfile=new File(item.getName());
                             String fileName = "";
                             String separator = "\\";
                             int pos = item.getName().lastIndexOf(separator);
                             int pos2 = item.getName().lastIndexOf(".");
                             if(pos2>-1){
                                  fileName =item.getName().substring(pos+1, pos2);
                             }else{
                                  fileName =item.getName().substring(pos+1);
                             File fileToBeUploaded=new File("C:\\Sal\\BPS MACRO\\FileTransfer\\Desti", fileName);
                             item.write(fileToBeUploaded);
                             validate.displaySuccessMessage(context);
              }catch(Exception e){System.out.println(e);
              Logger.debug(this.getClass(), METHOD_NAME, "Leaving BPSMacroPortlet");
              super.doView(arg0, arg1);
    ==== END: doView method in the portle class. ================================
    Thanks.

    one more question. Is there a way where I can submit two forms ?
    Thats is submit 2nd form only when the first form is submitted.
    I tried this it works.
    function formSubmit(){
    document.form1.submit();
    alert();
    document.form2.submit();
    But If I dont put an alert(basically it disables the parent page) in between, only the second form is submitted.
    If I put a delay of say 3 seconds in between then it will throw a SOCKET CLOSED error in the code triggered due to first form submit.
    Thus disabling the paresnt page for a few seconds is reolving my problem.
    Any ideas ?
    Well Basically when the Alert pop's up the parent page "STALLS" and thus the form2 does not submit till I click on OK, Is there a way I can stall the browser/Parent JSP page using JAVA SCRIPT ??
    Edited by: hector on Oct 9, 2007 11:09 AM
    Edited by: hector on Oct 9, 2007 2:12 PM

  • Strange Problem - All of my preloaded .swf files play at once

    Hey guys,
      I've been getting a strange problem that I haven't been able to debug.  I recently developed an interactive audio and video treatment program that users click through in which a master swf file (DTM-Start.swf) uses ActionScript upon first being loaded to load the rest of the program in the background.  Here's how the code looks: 
    import flash.display.MovieClip;
    import flash.display.Loader;
    import flash.net.URLRequest;
    import flash.events.Event;
    // create movieclip objects to hold the loaded movies
    var intr1:MovieClip;
    var maladaptIntr1:MovieClip;
    var maladaptIntr1Loader:Loader = new Loader();
    var maladaptIntr1Request:URLRequest = new URLRequest("DTM-Maladapt1.swf");
    maladaptIntr1Loader.load(maladaptIntr1Request);
    maladaptIntr1Loader.contentLoaderInfo.addEventListener(Event.COMPLETE, maladaptIntr1Loaded);
    var intr1Loader:Loader = new Loader(); 
    var intr1Request:URLRequest = new URLRequest("DTM-Intr1.swf");
    intr1Loader.load(intr1Request);
    intr1Loader.contentLoaderInfo.addEventListener(Event.COMPLETE, intr1Loaded);
    function maladaptIntr1Loaded(event:Event):void
        maladaptIntr1 = event.currentTarget.content as MovieClip;
        maladaptIntr1.stop();
        addChild(maladaptIntr1);
        maladaptIntr1.y = -1000
        trace("maladaptIntr1");
    function intr1Loaded(event:Event):void
        intr1 = event.currentTarget.content as MovieClip;
        intr1.stop();
        addChild(intr1);
        intr1.y = -1000
        trace("intr1");
    function playIntr1() {
       intr1.y = 0;
       intr1.play();
    function playMaladapt1() {
        maladaptIntr1.y = 0;
        maladaptIntr1.play();
    So that's the idea.  What's strange is that when I load a .swf file compiled with AIR 2.6 (because the user interacts with the movie and a text file is output) it's fine too, but as soon as I add any actionscript, even if it's just a stop() command, to a .swf file compiled with AIR, the DTM-Start.swf loads and then plays all of the movies simultaneously so they're all going off at once.  Essentially, flash seems to be ignoring the maladaptIntr.stop() command in the Loaded function, for instance.  I just don't understand why adding any Actionscript whatsoever to a .swf compiled with AIR would make my DTM-Start do this.  I am very confident this is the issue too, because loading .swf files compiled with the FlashPlayer with action script are fine...AIR .swf files without Actionscript are fine too, it's only AIR .swf files with ANY actionscript that cause this problem....
    Any ideas?
    Much appreciated!
    Thanks,
    Ricky

    One solution is simply to have a stop() in the constructor of the document Class of each swf you're loading. Another solution is something like:
    package {
         class MainDocument extends MovieClip {
         protected var swfs:Array = ['DTM-Maladapt1.swf', 'DTM-Intr1.swf'];
         protected var positions:Array = [{x:0, y:0}, {x:0, y:0}];
         protected var movies:Array /*of  MovieClips*/ = [];
         protected var loadIndex:int;
         protected var playIndex:int;
         protected var curremtMovie:MovieClip;
              public function MainDocument() {
                   super();
                   loadMovie(loadIndex);
              protected function loadMovie(loadIndex:int):void {
                   var loader:Loader = new Loader;
                   loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
                   loader.load(new URLRequest(swfs[loadIndex]));
              protected function onLoadComplete(e:Event):void {
                   var mc:MovieClip = LoaderInfo(e.currentTarget).content as MovieClip;
                   mc.stop();
                   var position:Object = positions[loadIndex];
                   mc.x = positions.x;
                   mc.y = positions.y;
                   addChild(mc);
                   movies[movies.length] = mc;
                   loadIndex++;
                   if (loadIndex<swfs.length) {
                        loadMovie(loadInxed);
                   } else {
                        playMovie(playIndex);
              protected function playMovie(playIndex):void{
                   if (currentMovie) {
                        currentMovie.stop();
                   currentMovie = movies[playIndex];
                   currentMovie.play();
    Note that with this approach you don't need to create a whole new set of logic each time you want to add a new swf to load.

Maybe you are looking for

  • BBP_PD

    Hello All....... please help me in understanding the screen bbp_pd, there are many things in that...looks like a big treasure. but i am unable to understand that. please tell me the important and useful things,what and where to look up.I didnt get th

  • ONLY SMALL IMAGE - in OS DVD PLAYER WINDOW

    Hi WHEN I USE THE OS dvd player sometimes it only is playing the dvd back as a small window with a big black boarder . If i check this by playing the dvd on my stand-alone dvd player/tv this does not happen. Could someone explain how i can change thi

  • How to create an Array of Object

    Is this correct: Object[] anArray = new Object[5]; Thanks.

  • Error after oracle software cloning

    Hi all , I have a database(10.2.0.5.0) in solaris 10 , i simply take a tar backup of ORACLE_HOME and extracted them into another server (which is solaris 10 only) and linked the binaries after that when i connecting with sqlplus i am getting followin

  • Extractor for Table BKPF

    Hi ,   I wanted to know the extractor for table BKPF . Where can i know or which is the extratcor Regards Ankit Vaish