Problem in file uploading to a temporary folder.
Hi all,
I am trying to upload a file to the server to a particular location D:/temp folder.The code I used is as below.It is not throwing any error but the file is not getting written on the server.
InputStream text;
int text=0;
try {
String location = "D:/temp";
String file1 = wdContext.currentContextElement().getFileName();
String file2 = location +file1;
File file = new File(file2);
FileOutputStream out = new FileOutputStream(file);
text = element.getFileResource().read(false);
while((temp=text.read())!=-1)
out.write(temp);
out.flush();
out.close();
String path = file.getAbsolutePath();
wdComponentAPI.getMessageManager().reportSuccess(path);
catch (IOException e2)
e2.printStackTrace();
Any clues please.
Regards,
rajesh.
Hi ,
If I use the below code it is working fine.The file is getting written on the K:\usr\sap\EPD\JC00\j2ee\cluster\server0\ .
But if I am tring to write the file in a specified path it is not creating the file.I think there is a problem in defining the path on the sever.can u help me on this.
InputStream text;
int text=0;
try {
File file = new File(wdContext.currentContextElement().getFileName);
FileOutputStream out = new FileOutputStream(file);
text = element.getFileResource().read(false);
while((temp=text.read())!=-1)
out.write(temp);
out.flush();
out.close();
String path = file.getAbsolutePath();
wdComponentAPI.getMessageManager().reportSuccess(path);
catch (IOException e2)
e2.printStackTrace();
Regards,
Rajesh
Similar Messages
-
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 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);
} -
Newbie : memory problem with file uploading
Hello
I'm exdending a web app based on jsf and , being new to it and java in general, i'm having a problem with file uploading.
The customer needs to upload large file (more than 30 MB). The application accomplish this using a fileupload component, to let the user select the file, and passing the array of bytes to a web service method.
I'm using netbeans 6, tomcat 5.5.
When i try to upload a file too large i got an outofmemory on the local tomcat. So i've rised jvm memory and going on with tests i've found that growing the size i got an http 500 error from the service (the developer of the service has found an out of memory too ).
I think the service is not modifiable, so i were asking if threre were a way to optimize the file uploading process (a component, a library, a pattern ...) or my only chioice is to rise available memory on both sides.
I've notice the wsdl declares as base64binary type the data parameter , while netbeans 6 generates a client proxy with a byte[] parameter. Is correct or is a netbeans problem?
searching with google i've found few thing i haven't fully understood due to my lack of experience:
the mtom , how can evaluate if it's suitable to help in my problem (i suppose it involves more the web service rather than the client)
something about the size of a soap body.
thank you in advance
StefanoWhich component exactly are you using? Declaring the stream as a raw byte[] is certainly not efficient. Write code yourself, don't let it autogenerate.
I can highly recommend you the Tomahawk t:inputFileUpload component. It is easy to integrate in Mojarra. You can find here an useful article: [http://balusc.blogspot.com/2008/02/uploading-files-with-jsf.html]. -
Problems with file uploading servlet, the form action doesnt capture url
Hi, i have one problem. I am working on a project , i have created a servlet that takes uploaded files and processses them and links them back to user to download. The servlet works perfectly from my computer, I am using apache-tomcat-6.0.16 and java 1.6 , I have two forms called encrypt.html and decrypt.html, I will post both of them, now the problem is when somebody access it on the internet while i am running apache, they get a connection was reset on a firefox browser and same stuff on Internet Explorer.
i have checked my server logs and saw nothing unusual there, So please if you can help me, it is my project.
I am pasting html file and error message that other users where getting remotely.
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
<title>Stego Form</title>
<link rel='STYLESHEET' type='text/css' href='encrypt.css'>
</head>
<body>
<center>
<form name='encrypt' enctype='multipart/form-data' method='POST' action='http://localhost:8080/examples/temp2
' accept-charset='UTF-8'>
<input type='hidden' name='sfm_form_submitted' value='yes'>
</input>
<input type='hidden' name='eord' value='e'>
<select name='encryption' size='1'>
<option value='Select an encryption' selected>
Select an encryption
</option>
<option value='DES'>
DES
</option>
<option value='Tripple DES'>
Tripple DES
</option>
</select>
<input type='file' name='overt' size='20'>
<input type='file' name='covert' size='20'>
<input type='submit' name='submit' value='Submit'>
</form>
</center>
</body>
</html>so it works for me even if i access the page with my ip , but for others it doesnt work,
now the user got this xhtml page that i will show, i cant find attach button so i am pasting here.
here is the servlet coding
import java.io.*;
import java.util.*;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import org.apache.commons.fileupload.*;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
public class temp2 extends HttpServlet
FileInputStream fin;
String filenames[] = new String[2],fieldname,fieldval;
String keyfile,IVfile;
String names[] = new String[2];
public temp2()
super();
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
doPost(request, response);
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
String eord="";
List lst = null;
boolean isMultiPart = ServletFileUpload.isMultipartContent(request);
if (!isMultiPart) // check whether the post request is actually multipart
System.out.println("ERROR NOT MULTIPART");
System.exit(0);
DiskFileItemFactory fif = new DiskFileItemFactory();
ServletFileUpload sfu = new ServletFileUpload(fif);
sfu.setSizeMax(10000000);
try { lst = sfu.parseRequest(request); }
catch (FileUploadException ex)
{ System.out.println("ERROR IN PARSING FILES" + ex); System.exit(0); }
if(lst.isEmpty()) // check whether request is empty
System.out.println("ERROR LIST SIZE NOT GOOD : " + lst.size());
System.exit(0);
Iterator x = lst.iterator();
int i = 0;
FileItem f = (FileItem)x.next();
f = (FileItem)x.next();
System.out.println(f.getFieldName());
if(f.getFieldName().equalsIgnoreCase("eord")) // check hidden field to know the case : encrypt or decrypt
eord = f.getString();
System.out.println(f.getString());
else // if it is not first field exit
System.out.println("Invalid FORM");
System.exit(0);
f = (FileItem)x.next(); // next field
if(f.getFieldName().equalsIgnoreCase("encryption")) // type of encryption des / tdes
fieldname = f.getFieldName();
fieldval = f.getString();
System.out.println(f.getString());
if(eord.equalsIgnoreCase("e")) // if it is encryption form only file required
while(x.hasNext())
f = (FileItem)x.next();
if(!f.isFormField())
int check = f.getName().lastIndexOf(File.separator);
System.out.println(File.separator);
if(check==-1)
System.out.println(f.getName());
System.out.println("Unsupported browser : " + check);
System.exit(0);
File ff = new File("e:\\apache\\webapps\\temp\\"+f.getName().substring(check));
names[i] = ff.getName(); // original file names
try
f.write(ff);
filenames[i] = ff.getAbsolutePath();
// renamed
ff.deleteOnExit();
}catch(Exception e) {System.out.println("Error writing file"+ ff.getAbsolutePath()); System.exit(0);}
i++;
try { System.in.read(); } catch(Exception e) {}
}// endwhile
if(fieldval.equalsIgnoreCase("DES"))
System.out.println("DES 1"+filenames[1]);
javades o = new javades(filenames[1]); // the file to be encrypted
filenames[1] = "e:\\apache\\webapps\\temp\\files\\" + names[1];
System.out.println("should be original" + filenames[1]);
else if(fieldval.equalsIgnoreCase("Tripple DES"))
javatdes o = new javatdes(filenames[1]);
filenames[1] = "e:\\apache\\webapps\\temp\\files\\" + names[1];
System.out.println(filenames[1]);
System.out.println("Calling stego");
filenames[0] = "e:\\apache\\webapps\\temp\\" + names[0];
System.out.println("file 1 "+ filenames[0]);
System.out.println("file 2"+ filenames[1]);
try { System.in.read(); } catch(Exception e) {}
stego s = new stego(filenames[0],filenames[1]);
System.out.println("mainext " + s.mainext);
// encryption done, and new files are loaded, now lets hide
if(s.mainext.equalsIgnoreCase("wav"))
s.encodewav();
System.out.println("Encoded wave");
else if(s.mainext.equalsIgnoreCase("bmp"))
System.out.println("Encoded bmp");
s.encodebmp();
System.out.println("done !");
PrintWriter pr = response.getWriter();
pr.println("Greetings , Your work is done and saved, now download the following files");
pr.println("The secret key file is needed for getting back your hidden file, so download that too");
pr.write("<a href=\"/temp/files/IV.txt\">click here</a>");
pr.write("<br/><a href=\"/temp/files/key.txt\">click here</a>");
pr.write("<br/><a href=\"/temp/files/"+names[0]+"\">click here</a>");
return;
// if it is decryption case
else if(eord.equalsIgnoreCase("d"))
while(x.hasNext())
f = (FileItem)x.next();
if(!f.isFormField())
int check = f.getName().lastIndexOf(File.separator);
System.out.println(File.separator);
if(check==-1)
System.out.println(f.getName());
System.out.println("Unsupported browser : " + check);
System.exit(0);
File ff = new File("e:\\apache\\webapps\\temp\\"+f.getName().substring(check));
// else if ladder to store paths of stegofile keyfile and IVfile
if(f.getFieldName().equalsIgnoreCase("stegofile"))
filenames[0] = ff.getAbsolutePath();
else if(f.getFieldName().equalsIgnoreCase("keyfile"))
keyfile = ff.getAbsolutePath();
else if(f.getFieldName().equalsIgnoreCase("IVfile"))
IVfile = ff.getAbsolutePath();
try
f.write(ff); // writes whole file at once
}catch(Exception e) {System.out.println("Error writing file"); System.exit(0);}
}// endwhile
System.out.println("Calling stego");
System.out.println("file 1 "+ filenames[0]);
stego s = new stego(filenames[0]);
System.out.println("mainext " + s.mainext);
if(s.mainext.equalsIgnoreCase("wav"))
s.decodewav();
System.out.println("Encoded wave");
else if(s.mainext.equalsIgnoreCase("bmp"))
s.decodebmp();
System.out.println("Encoded bmp");
System.out.println("done !");
////// hidden file has been retrieved , now lets decrypt it
System.out.println("ext " + s.ext);
filenames[0] = "e:\\apache\\webapps\\temp\\"+s.filename;
System.out.println(filenames[0]);
System.out.println(keyfile);
System.out.println(IVfile);
if(fieldval.equalsIgnoreCase("DES"))
javades o = new javades(filenames[0],keyfile,IVfile); // the file to be encrypted
filenames[0] = "e:\\apache\\webapps\\temp\\" + ( new File(filenames[0]).getName());
System.out.println("should be original" + filenames[0]);
else if(fieldval.equalsIgnoreCase("Tripple DES"))
javatdes o = new javatdes(filenames[0],keyfile,IVfile);
filenames[0] = "e:\\apache\\webapps\\temp\\" + ( new File(filenames[0]).getName());
System.out.println(filenames[0]);
PrintWriter pr = response.getWriter();
pr.write("Greetings, you have successfully retrieved your hidden file, now download it from here <br>");
pr.write("<a href=\"http://localhost:8080/temp/files/" + (new File(filenames[0]).getName())+"\">Click here</a>");
}and here is the xhtml file the user receives, whe he clicks the submit button,
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html [
<!ENTITY % htmlDTD
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"DTD/xhtml1-strict.dtd">
%htmlDTD;
<!ENTITY % netErrorDTD
SYSTEM "chrome://global/locale/netError.dtd">
%netErrorDTD;
<!ENTITY loadError.label "Problem loading page">
<!ENTITY retry.label "Try Again">
<!-- Specific error messages -->
<!ENTITY connectionFailure.title "Unable to connect">
<!ENTITY connectionFailure.longDesc "&sharedLongDesc;">
<!ENTITY deniedPortAccess.title "This address is restricted">
<!ENTITY deniedPortAccess.longDesc "">
<!ENTITY dnsNotFound.title "Server not found">
<!ENTITY dnsNotFound.longDesc "
<ul>
<li>Check the address for typing errors such as
<strong>ww</strong>.example.com instead of
<strong>www</strong>.example.com</li>
<li>If you are unable to load any pages, check your computer's network
connection.</li>
<li>If your computer or network is protected by a firewall or proxy, make sure
that &brandShortName; is permitted to access the Web.</li>
</ul>
">
<!ENTITY fileNotFound.title "File not found">
<!ENTITY fileNotFound.longDesc "
<ul>
<li>Check the file name for capitalization or other typing errors.</li>
<li>Check to see if the file was moved, renamed or deleted.</li>
</ul>
">
<!ENTITY generic.title "Oops.">
<!ENTITY generic.longDesc "
<p>&brandShortName; can't load this page for some reason.</p>
">
<!ENTITY malformedURI.title "The address isn't valid">
<!ENTITY malformedURI.longDesc "
<ul>
<li>Web addresses are usually written like
<strong>http://www.example.com/</strong></li>
<li>Make sure that you're using forward slashes (i.e.
<strong>/</strong>).</li>
</ul>
">
<!ENTITY netInterrupt.title "The connection was interrupted">
<!ENTITY netInterrupt.longDesc "&sharedLongDesc;">
<!ENTITY netOffline.title "Offline mode">
<!ENTITY netOffline.longDesc "
<ul>
<li>Uncheck "Work Offline" in the File menu, then try again.</li>
</ul>
">
<!ENTITY netReset.title "The connection was reset">
<!ENTITY netReset.longDesc "&sharedLongDesc;">
<!ENTITY netTimeout.title "The connection has timed out">
<!ENTITY netTimeout.longDesc "&sharedLongDesc;">
<!ENTITY protocolNotFound.title "The address wasn't understood">
<!ENTITY protocolNotFound.longDesc "
<ul>
<li>You might need to install other software to open this address.</li>
</ul>
">
<!ENTITY proxyConnectFailure.title "The proxy server is refusing connections">
<!ENTITY proxyConnectFailure.longDesc "
<ul>
<li>Check the proxy settings to make sure that they are correct.</li>
<li>Contact your network administrator to make sure the proxy server is
working.</li>
</ul>
">
<!ENTITY proxyResolveFailure.title "Unable to find the proxy server">
<!ENTITY proxyResolveFailure.longDesc "
<ul>
<li>Check the proxy settings to make sure that they are correct.</li>
<li>Check to make sure your computer has a working network connection.</li>
<li>If your computer or network is protected by a firewall or proxy, make sure
that &brandShortName; is permitted to access the Web.</li>
</ul>
">
<!ENTITY redirectLoop.title "The page isn't redirecting properly">
<!ENTITY redirectLoop.longDesc "
<ul>
<li>This problem can sometimes be caused by disabling or refusing to accept
cookies.</li>
</ul>
">
<!ENTITY unknownSocketType.title "Unexpected response from server">
<!ENTITY unknownSocketType.longDesc "
<ul>
<li>Check to make sure your system has the Personal Security Manager
installed.</li>
<li>This might be due to a non-standard configuration on the server.</li>
</ul>
">
<!ENTITY sharedLongDesc "
<ul>
<li>The site could be temporarily unavailable or too busy. Try again in a few
moments.</li>
<li>If you are unable to load any pages, check your computer's network
connection.</li>
<li>If your computer or network is protected by a firewall or proxy, make sure
that &brandShortName; is permitted to access the Web.</li>
</ul>
">
<!ENTITY % globalDTD
SYSTEM "chrome://global/locale/global.dtd">
%globalDTD;
]>
<!-- ***** BEGIN LICENSE BLOCK *****
- Version: MPL 1.1/GPL 2.0/LGPL 2.1
- The contents of this file are subject to the Mozilla Public License Version
- 1.1 (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
- http://www.mozilla.org/MPL/
- Software distributed under the License is distributed on an "AS IS" basis,
- WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- for the specific language governing rights and limitations under the
- License.
- The Original Code is mozilla.org code.
- The Initial Developer of the Original Code is
- Netscape Communications Corporation.
- Portions created by the Initial Developer are Copyright (C) 1998
- the Initial Developer. All Rights Reserved.
- Contributor(s):
- Adam Lock <[email protected]>
- William R. Price <[email protected]>
- Henrik Skupin <[email protected]>
- Jeff Walden <[email protected]>
- Alternatively, the contents of this file may be used under the terms of
- either the GNU General Public License Version 2 or later (the "GPL"), or
- the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- in which case the provisions of the GPL or the LGPL are applicable instead
- of those above. If you wish to allow use of your version of this file only
- under the terms of either the GPL or the LGPL, and not to allow others to
- use your version of this file under the terms of the MPL, indicate your
- decision by deleting the provisions above and replace them with the notice
- and other provisions required by the LGPL or the GPL. If you do not delete
- the provisions above, a recipient may use your version of this file under
- the terms of any one of the MPL, the GPL or the LGPL.
- ***** END LICENSE BLOCK ***** -->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Problem loading page</title>
<link rel="stylesheet" href="temp2_files/netError.css" type="text/css" media="all"/>
<!-- XXX this needs to be themeable -->
<link rel="icon" type="image/png" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAANbY1E9YMgAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAICSURBVHjaYvz//z8DJQAggJhwiDPvnmlzc2aR0O+JGezt+AwACCCsBhxfYhn59N41FWtXIxZOLu70niRGXVwGAAQQNgNYHj96O8HaWYdJW5ubwd4/mI2Ng7sblwEAAYRhwMm1URk/vn4SUNWVYGD8+YZBXZOZm5OLzRjoCmNsBgAEEKoBN82Y7l851GLrqMjM8Oc7A8O/3wwMP54wuAQFCXNycUzGZgBAAKEYcOaKZO2/f//5FbUVgBrfMoRVcgHpNwyKGjKMXDwCan0prFboBgAEELIBzDcvXyy2cVZhYPj9GWj7H4jo/38MDJ9OMDj7O/KzsjH3oxsAEEBwA/bNNipiZf7FI6cqwcDw8x2qqp8fGORUpVn4BEXlgGHhhCwFEEAwA9gfP3hdZ+Oizcjw+wvCdjgAuuLrFQbXIH9hTm7uqcgyAAEENuD4ctcebm5mbikFYRTbV7V/Q6j88Z5BSuY7q4CQgAjQFR4wYYAAAhtw89L5ZFsnRaDtn4CW/YXrAQcisit+PGVwDgrnZ2NnnwATBQggpsNLvGYLCAmxi8tLARWg+h3FBVBXSEj/ZZWQkRcCuiIQJAQQQCyvnj5KMDTkZ2JgYmRg4FchnHv+vmEwttLmeXT3VjKQtx4ggFgk5TXebV63UfT3ijOMxOZAVlZWdiB1EMQGCCBGSrMzQIABAFR3kRM3KggZAAAAAElFTkSuQmCC"/>
<script type="application/x-javascript"><![CDATA[
// Error url MUST be formatted like this:
// moz-neterror:page?e=error&u=url&d=desc
// Note that this file uses document.documentURI to get
// the URL (with the format from above). This is because
// document.location.href gets the current URI off the docshell,
// which is the URL displayed in the location bar, i.e.
// the URI that the user attempted to load.
function getErrorCode()
var url = document.documentURI;
var error = url.search(/e\=/);
var duffUrl = url.search(/\&u\=/);
return decodeURIComponent(url.slice(error + 2, duffUrl));
function getDescription()
var url = document.documentURI;
var desc = url.search(/d\=/);
// desc == -1 if not found; if so, return an empty string
// instead of what would turn out to be portions of the URI
if (desc == -1) return "";
return decodeURIComponent(url.slice(desc + 2));
function retryThis()
// Session history has the URL of the page that failed
// to load, not the one of the error page. So, just call
// reload(), which will also repost POST data correctly.
try {
location.reload();
} catch (e) {
// We probably tried to reload a URI that caused an exception to
// occur; e.g. a non-existent file.
function initPage()
var err = getErrorCode();
// if it's an unknown error or there's no title or description
// defined, get the generic message
var errTitle = document.getElementById("et_" + err);
var errDesc = document.getElementById("ed_" + err);
if (!errTitle || !errDesc)
errTitle = document.getElementById("et_generic");
errDesc = document.getElementById("ed_generic");
var title = document.getElementById("errorTitleText");
if (title)
title.parentNode.replaceChild(errTitle, title);
// change id to the replaced child's id so styling works
errTitle.id = "errorTitleText";
var sd = document.getElementById("errorShortDescText");
if (sd)
sd.textContent = getDescription();
var ld = document.getElementById("errorLongDesc");
if (ld)
ld.parentNode.replaceChild(errDesc, ld);
// change id to the replaced child's id so styling works
errDesc.id = "errorLongDesc";
// remove undisplayed errors to avoid bug 39098
var errContainer = document.getElementById("errorContainer");
errContainer.parentNode.removeChild(errContainer);
]]></script>
</head>
<body dir="ltr">
<!-- ERROR ITEM CONTAINER (removed during loading to avoid bug 39098) -->
<!-- PAGE CONTAINER (for styling purposes only) -->
<div id="errorPageContainer">
<!-- Error Title -->
<div id="errorTitle">
<h1 id="errorTitleText">The connection was reset</h1>
</div>
<!-- LONG CONTENT (the section most likely to require scrolling) -->
<div id="errorLongContent">
<!-- Short Description -->
<div id="errorShortDesc">
<p id="errorShortDescText">The connection to the server was reset while the page was loading.</p>
</div>
<!-- Long Description (Note: See netError.dtd for used XHTML tags) -->
<div id="errorLongDesc">
<ul>
<li>The site could be temporarily unavailable or too busy. Try again in a few
moments.</li>
<li>If you are unable to load any pages, check your computer's network
connection.</li>
<li>If your computer or network is protected by a firewall or proxy, make sure
that Firefox is permitted to access the Web.</li>
</ul>
</div>
</div>
<!-- Retry Button -->
<xul:button xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" id="errorTryAgain" label="Try Again" oncommand="retryThis();"/>
</div>
<!--
- Note: It is important to run the script this way, instead of using
- an onload handler. This is because error pages are loaded as
- LOAD_BACKGROUND, which means that onload handlers will not be executed.
-->
<script type="application/x-javascript">initPage();</script>
</body>
</html>thank you for your prompt reply in advance,
Regards,
Mihir PandyaHi, thank you for your replies, I found out few things about my servlet, and its portability
and i have few questions, although i marked this topic as answered i guess its ok to post
I am using javax.servlet.context.tempdir to store my files in that servletcontext temporary directory. But i dont know how to give hyperlink
of the modified files to the user for them to download the modified files.
What i am using to get the tempdir i will paste
File baseurl = (File)this.getServletContext().getAttribute("javax.servlet.context.tempdir");
System.out.println(baseurl);
baseurl = new File(baseurl.getAbsolutePath()+File.separator+"temp"+File.separator+"files");
baseurl.mkdirs();so i am storing my files in that temp/files folder and the servlet processes them and modifies them, then how to present them as
links to the user for download ?
and as the servlet is multithreaded by nature, if my servlet gets 2 different requests with same file names, i guess one of them will be overwritten
And i want to create unique directory for each request made to the servlet , so file names dont clash.
one another thing is that i want my servlet to be executed by my <form action> only, I dont want the user to simply type url and trigger the servlet
Reply A.S.A.P. please..
Thanks and regards,
Mihir Pandya -
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 -
Hi,
I have located this folder and files in my C:Temp Directory(Normally C:Windows/temp).
CompatTelemetryLogs with
AppAndDeviceInventory.log right next to it.
and the following inside the folder.
Folder = "IMG" lots of little image files of all my software
Folder = "Resources" with nothing in it.
Files:
CompatData_2014_10_17_06_04_14_1_008001ff.xml
compatscancache.dat
DeviceGroupingRules.xml
diagerr.xml
diagwrn.xml
PreliminaryReport.xml
setupact.log
setuperr.log
TelemetryTransform.xsl
WICA_Devices_SOL.xml
WICA_Programs_SOL.xml
WICA_QueryAppBlock_SOL.xml
WICA_QueryBiosBlock_SOL.xml
WICA_QueryDeviceBlock_SOL.xml
WICA_System_SOL.xml
WICA_SystemReport_SOL.xml
WICA_TelemetryReport_SOL.xml
WicaDeviceFilters.xml
Windows_TelemetryData.xml
Not sure about all of these but I did a search for this one: "TelemetryTransform.xsl" and one entry was this below(except I do not have any office program installed form MS, I use Open Office) http://technet.microsoft.com/en-us/library/jj219431%28v=office.15%29.aspx
And this one: "Windows_TelemetryData.xml"
https://www.google.com/search?num=100&safe=off&hl=en&site=webhp&source=hp&q=Windows_TelemetryData.xml&oq=Windows_TelemetryData.xml&gs_l=hp.12...6809.28780.4.29973.3.3.0.0.0.0.82.216.3.3.0.ccynfh...0...1.1.56.hp..14.0.0.0.KGgYvIjDHXA
I am not attempting to install windows 8? at all so why this is coming up is beyond me I am using Win7 64 Pro and am quite happy with that version.
Is all of this just some attempt at someone to install windows 8 on my system through the comcast internet system?
I also have now searched for the file that was next to the folder: "AppAndDeviceInventory.log" and got this:
http://www.exclusive-networks.be/Vendors/mobileiron/
It looks like someone is or has installed an application to make my windows send data over the internet or network. Making my entire windows system hosed with this. Or has someone any idea of how to get rid of it?
Thanks ahead!Hi,
These files are just some temporary file created by using the system. You could delete them manually via disk cleanup:
Delete files using Disk Cleanup
http://windows.microsoft.com/en-us/windows/delete-files-using-disk-cleanup#delete-files-using-disk-cleanup=windows-7
Karen Hu
TechNet Community Support -
Hi all, my problem has something to do with internal working of pageflow.
Here is what has happened:
1. I have a page with a few portlets on it.
2. One of the portlet is for uploading file (lets call it upload portlet)
3. The rest of the portlet need to access the PortletBackingContext using the following code (put in a jpf):
PortletBackingContext portletCtx = PortletBackingContext.getPortletBackingContext(super.getRequest());
4. When the upload portlet transfers the file, the other portlets will refresh (i'm using refreshAction attribute).When the other portlets refresh, they can't get the PortletBackingContext. It always returns null.
If I remove the enctype="multipart/form-data" from the netui:form tag, it works as per normal (but of course the file uploading fails).
Any idea?
Thanks.
panji.a
[att1.html]This post may be useful:
http://forums.bea.com/bea/message.jspa?messageID=600021968&tstart=0 -
Facing problem during file upload
hi
we r designing a portal where it is required to upload files based on individual users who have logged in.
For this purpose we r using a file field in one page and http upload tag in another page.
The file uploads successfuly to the database, but the problem is that we r not able to get the value of pReq.getUser() in the page where the httpfileupload tag exists.
we noted that request.getParameter() and session.getValue() is also not valid in this page.
we also tried setting the session value to true in provider.xml. Even this didnt work.
we noted that this problem comes only when the file field is used. can anyone tell me how to solve this??
Thanks in advance.
voyagerrequest.getParameter() nor session.getParameter() does not fetch anything. the value is null
Regards,
voyager -
Hello all. Has anybody successfully got the UploadFilter classes -- as listed in Hortsmann and Geary's "Core JSF" -- going?
Everytime I submit a multipart form, I am not redirected to the appropriate next page (as specified in the navigation cases) . I have definitely set up the UploadFilter correctly, and any multipart form requests are getting parsed and uploaded into the correct directory. The only problem is that the resulting page isn't the one specified in faces-config.xml -- it's the original upload page.
If I get rid of the multipart/form-data encoding for the form, it works "okay" (in the sense that the file upload no longer works, but the behaviour matches the navigation cases).
I'm beginning to wonder whether the fact the form is a multipart form means that the submit button's action -- which is set to "submit", matching a value in faces-config.xml -- isn't being correctly parsed. Are there any "gotchas" I should be aware of in these cirumstances?Hi diritchie,
perhaps that thread helps you.
http://forum.java.sun.com/thread.jsp?forum=427&thread=473135
There are posts of some clazzes, to enable upload.
the clazzes are using Jakarta Commons FileUpload
btw. in MyFaces there is allready an upload-component.
Regards,
Matthias -
Can anybody provide the SQL query to find the files uploaded in a particular folder?
Hi All,
Can anybody provide the SQL query to find the documents (document name) uploaded in a particular folder? While clicking on folder in
GUI I'm hitting the Timeout error. I would like to find the files uploaded into this folder from SQLPLUS.
Any help is greatly appreciated.
With best regards,
NevinNevin,
Be great if we could know the version of Portal. For Rel. 1, here's the query
select id,masterthingid from wwv_things
where siteid = &site
and cornerid = &corner
&site - Content Area id
&corner - Folder id
if you don't know the folder id, use
select id from wwv_corners where siteid = &site
and name = &folder
Hope this helps. I have run into this situation before. Usually, the culprits were
one of the following:
1. Junk Characters in description of item (caused due to Copy-Paste)
2. Special Characters in the File name
Hi All,
Can anybody provide the SQL query to find the documents (document name) uploaded in a particular folder? While clicking on folder in
GUI I'm hitting the Timeout error. I would like to find the files uploaded into this folder from SQLPLUS.
Any help is greatly appreciated.
With best regards,
Nevin -
Problems with file upload using AMF or SOAP
We use your AMF to connect Flex with Ruby on Rails.
Everything is OK, except file upload.
We did not find how to upload file using AMF or SOAP RPC from
Flex. Only to use FileReference.upload().
The problem is that Flex uses different User-Agent in HTTP
header for this upload and for SOAP/AMF calls.
This means that sessions are different. And even if you
authenticated via SOAP/AMF you can not use it to upload file.
Could you, please, advice is there any other way to upload
files from Flex via SOAP or AMF?Please, help me on this issue, i am still waiting for someone replying me!
-
Problems with File Upload on BEA WLS 6.1
I encountered a problem with Jason Hunters File Upload Classes.
When uploading a file I always get this exception:
java.lang.NoClassDefFoundError: javax/servlet/http/HttpServletRequest
at com.oreilly.servlet.MultipartRequest.<init>(MultipartRequest.java:175)
at servlets.uploader.service(uploader.java:21)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:263)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:200)
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:23
90)
at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:1959)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:137)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
The line of code that brings up this exception is:
multiReq = new MultipartRequest((ServletRequest)request, "c:\\temp", 10485760);
Going directly with the HttpServletRequest doesn't help.
Can anybody help me out on this one? Thanks in forward.
MichaelThe line of code that brings up this exception is:
multiReq = new
= new MultipartRequest((ServletRequest)request,
"c:\\temp", 10485760);
try this: MultipartRequest multiReq = new MultipartRequest((ServletRequest)request,
"c:\\temp", 10485760);
(not sure if that is the problem or not..) -
Problem using File upload in portlets
hello there
I'm trying to use file upload component in one of my portlets. I searched a lot about a working component to be used in portlets since the standard one that comes with JSC doesn't work in portlets. I managed to get commons file upload and tomahawk to run in my portlet, but when I choose a file and try to get selected file's details it throughs a NullPointerException reporting that the file object is null.
so please can anyone guide me to a working portlet example, I tried to find one but I couldn't. if that's hard to find, what should I do ?
thank you in advanceI added file upload component in JSF from portlets in Sun Java Portal server.
Take a look...
portlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"
version="1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd">
<portlet>
<description>SFTB Anonymous Mail Portlet</description>
<portlet-name>SFTBAnonymousMailPortlet</portlet-name>
<display-name>SFTBAnonymousMailPortlet</display-name>
<portlet-class>org.apache.portals.bridges.portletfilter.FilterPortlet</portlet-class>
<init-param>
<name>portlet-class</name>
<value>com.sun.faces.portlet.FacesPortlet</value>
</init-param>
<!-- Filter for MyFaces Tomahawk extension. -->
<init-param>
<name>portlet-filters</name>
<value>jp.sf.pal.tomahawk.filter.ExtensionsPortletFilter</value>
</init-param>
<init-param>
<description>Portlet init page</description>
<name>com.sun.faces.portlet.INIT_VIEW</name>
<value>/jsp/index.jsp</value>
</init-param>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>VIEW</portlet-mode>
<portlet-mode>EDIT</portlet-mode>
<portlet-mode>HELP</portlet-mode>
</supports>
<portlet-info>
<title>Отправка предложений</title>
<short-title>Отправка предложений</short-title>
</portlet-info>
</portlet>
</portlet-app>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>SFTBAnonymousMailComment</display-name>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>/WEB-INF/faces-config.xml</param-value>
</context-param>
<!--
Extensions filter from Apache MyFaces Tomahawk used for uploads files.
-->
<filter>
<filter-name>ExtensionsFilter</filter-name>
<filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class>
<init-param>
<param-name>uploadMaxFileSize</param-name>
<param-value>10m</param-value>
<description>Set the size limit for uploaded files.
Format: 10 - 10 bytes
10k - 10 KB
10m - 10 MB
1g - 1 GB
</description>
</init-param>
<init-param>
<param-name>uploadThresholdSize</param-name>
<param-value>100k</param-value>
<description>Set the threshold size - files
below this limit are stored in memory, files above
this limit are stored on disk.
Format: 10 - 10 bytes
10k - 10 KB
10m - 10 MB
1g - 1 GB
</description>
</init-param>
</filter>
<filter-mapping>
<filter-name>ExtensionsFilter</filter-name>
<servlet-name>FacesServlet</servlet-name>
</filter-mapping>
<servlet>
<servlet-name>FacesServlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>FacesServlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
</web-app>
Files in WEB-INF/lib
commons-beanutils-1.7.0.jar
commons-collections-3.2.jar
commons-digester-1.8.jar
commons-fileupload-1.2.1.jar
commons-io-1.2.jar
commons-logging-1.1.1.jar
faces-response-filter-0.2.jar
jsf-api-1.1_02.jar
jsf-impl-1.1_02.jar
jsf-portlet-1.1.5.jar
jstl-1.1.0-D13.jar
log4j-1.2.9.jar
portals-bridges-portletfilter-1.0.jar
standard-1.1.0-D13.jar
tomahawk-1.1.6.jar
tomahawk-bridge-0.9.1.jar
Files tomahawk-bridge-0.9.1.jar, faces-response-filter-0.2.jar may be found there http://sourceforge.jp/projects/pal/
In JSF beans I'm using org.apache.myfaces.custom.fileupload.UploadedFile
Hope this helps.
Bests,
Alex Magdenko -
Problem with file upload in JDeveloper 10.1.2 version
Hi,
My application is running in JDveloper 10.1.2.1 version with BC4J Struts. Now, I want to do a module with file upload. I am getting an error in the uploading section as
java.lang.NullPointerException
at oracle.jbo.html.struts11.MultipartUtil.populate(MultipartUtil.java:227)
at oracle.jbo.html.struts11.BC4JRequestProcessor.processPopulate(BC4JRequestProcessor.java:433)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:254)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.evermind[Oracle Application Server Containers for J2EE 10g (10.1.2.2.0)].server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:65)
at oracle.security.jazn.oc4j.JAZNFilter.doFilter(Unknown Source)
at com.evermind[Oracle Application Server Containers for J2EE 10g (10.1.2.2.0)].server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:673)
at com.evermind[Oracle Application Server Containers for J2EE 10g (10.1.2.2.0)].server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:340)
at com.evermind[Oracle Application Server Containers for J2EE 10g (10.1.2.2.0)].server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:830)
at com.evermind[Oracle Application Server Containers for J2EE 10g (10.1.2.2.0)].server.http.HttpRequestHandler.run(HttpRequestHandler.java:285)
at com.evermind[Oracle Application Server Containers for J2EE 10g (10.1.2.2.0)].server.http.HttpRequestHandler.run(HttpRequestHandler.java:126)
at com.evermind[Oracle Application Server Containers for J2EE 10g (10.1.2.2.0)].util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:192)
at java.lang.Thread.run(Thread.java:534)
Please suggest me an option to resolve the issue.
Regards,
Jobz....I remember that there was a bug in the MultipartHandler of the BC4JRequestProcessor in one of the 10.1.2.x version, however I'm nit sure which one. I found the old fix we implemented back then
Try this request processor and see if this helps:
package xx.yy.zz.common;
import javax.servlet.http.HttpServletResponse;
import oracle.jbo.html.struts11.BC4JActionMapping;
import org.apache.struts.Globals;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.upload.MultipartRequestHandler;
import org.apache.struts.upload.MultipartRequestWrapper;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import oracle.jbo.html.HtmlServices;
import oracle.jbo.html.struts11.BC4JRequestProcessor;
import oracle.jbo.html.struts11.MultipartUtil;
* RequestProcessor for Apache Struts based applicartions
* Fix for a bug in <code>BC4JRequestProcessor</code> Multipart-Requests (e.g. Upload).
* @projekt common
public class HvbgBC4JRequestProcessor extends BC4JRequestProcessor {
* Override to fix a bug. Note that this works only if all ActionMappings in the project
* are of the type BC4JActionMapping.
* @see oracle.jbo.html.struts11.BC4JRequestProcessor#processMultipart(HttpServletRequest) processMultipart
protected HttpServletRequest processMultipart(HttpServletRequest request)
// Overide only if the action mapping is a BC4JActionMapping.
BC4JActionMapping mapping = (BC4JActionMapping) request.getAttribute(Globals.MAPPING_KEY);
if (HtmlServices.isMultipartPost(request)) {
MultipartRequestHandler handler = MultipartUtil.retrieveMultipartHandler(request);
if (handler == null) {
try {
request = MultipartUtil.parseMultipartRequest(request, servlet);
catch (ServletException se) {
throw new RuntimeException(se.getMessage());
else {
// This is a forward from a Multipart Post upload
if (!(request instanceof MultipartRequestWrapper)) {
request = new MultipartRequestWrapper(request);
MultipartUtil.setWrapperParams(handler, (MultipartRequestWrapper) request);
else {
// do nothing
return (request);
Don't forget to set this new class in your struts-config.xml file!
Timo
Maybe you are looking for
-
I have half my film in 1080 and half in 720. I can set my timeline to be in either or, but not both. When it plays 720, the 1080 is scrambled colored snow and vice-a-versa. I found a way to fix this in the help section but I can not navigate back the
-
I cant seem to type in the address bar
when i click in the address bar i cant seem to type anything. nothing shows up in the bar. what could be wrong?
-
Hello - I live in the UAE and my itunes account is regsitered here. Unfortunately the choice of music is not as good as when my account was registered in the UK. I cannot register my account in the UK as my bank details are all in the UAE now. HELP!
-
Save as option in WAD 3.x
Hi All, I am using WAD 3.x(customer request), I want to download the file to Excel(or .pdf format). Is there any standard template to export the file. Thanks and Regards, Sheeba
-
Loading masterdata and transaction data from same flat file
hi all, how can i load master data and transaction data from the same flatfile at a time.