本文整理匯總了Java中org.apache.commons.fileupload.FileUploadException.printStackTrace方法的典型用法代碼示例。如果您正苦於以下問題:Java FileUploadException.printStackTrace方法的具體用法?Java FileUploadException.printStackTrace怎麽用?Java FileUploadException.printStackTrace使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.fileupload.FileUploadException
的用法示例。
在下文中一共展示了FileUploadException.printStackTrace方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: MultiPartEnabledRequest
import org.apache.commons.fileupload.FileUploadException; //導入方法依賴的package包/類
public MultiPartEnabledRequest(HttpServletRequest req)
{
super(req);
this.multipart = FileUpload.isMultipartContent(req);
if (multipart)
{
try
{
readHttpParams(req);
}
catch (FileUploadException e)
{
Trace.write(Trace.Error,e, "MultiPartEnabledRequest");
e.printStackTrace();
}
}
}
示例2: initialize
import org.apache.commons.fileupload.FileUploadException; //導入方法依賴的package包/類
@Override
protected void initialize()
{
if( ( request.getMethod().equals( Method.POST ) || request.getMethod().equals( Method.PUT ) ) && request.isEntityAvailable() && request.getEntity().getMediaType().includes( MediaType.MULTIPART_FORM_DATA ) )
{
try
{
for( FileItem fileItem : fileUpload.parseRequest( request ) )
{
if( fileItem.isFormField() )
formFields.put( fileItem.getFieldName(), fileItem.getString() );
else
map.put( fileItem.getFieldName(), Collections.unmodifiableMap( createFileItemMap( fileItem ) ) );
}
}
catch( FileUploadException x )
{
x.printStackTrace();
}
}
}
示例3: createMultipartForm
import org.apache.commons.fileupload.FileUploadException; //導入方法依賴的package包/類
/**
* 讀取表單中的參數
* eg:普通文本或文件
* @param request
* @return
*/
public static void createMultipartForm(RequestParam params ,HttpServletRequest request){
//Parse the request
try {
List<FileItem> items = fileUpload.parseRequest(request);
// Process the uploaded items
Iterator<FileItem> iter = items.iterator();
while (iter.hasNext()) {
FileItem item = iter.next();
if (item.isFormField()) {
processFormField(params,item);
} else {
processUploadedFile(params,item);
}
}
} catch (FileUploadException e) {
logger.error("File Upload Failure :" +e );
e.printStackTrace();
}
}
示例4: getValueFromUploadForm
import org.apache.commons.fileupload.FileUploadException; //導入方法依賴的package包/類
/**
* 功能: 從上傳的request中得到普通字符值,一定要注意隻能調用一次
* @param request
* @param fieldName
* @return
*/
public static String getValueFromUploadForm(HttpServletRequest request, String fieldName) {
String returnValue = null;
try {
DiskFileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload sfu = new ServletFileUpload(factory);
List lItems = sfu.parseRequest(request);
java.util.Iterator iter = lItems.iterator();
while (iter.hasNext()) {
FileItem item = (FileItem) iter.next();
if (fieldName.equals(item.getFieldName())) {
returnValue = item.getString();
break;
}
}
} catch (FileUploadException e) {
e.printStackTrace();
}
return returnValue;
}
示例5: handleServlet
import org.apache.commons.fileupload.FileUploadException; //導入方法依賴的package包/類
/**
*
* processes HTTP-Requests by extracting the form-data. If extraction is
* successful, data is passed to checkRequestParameter() which also takes on
* generating a response. If extraction fails a response containing an
* error-message is returned.
*
* @param request
* @param context
* @author Christian Schowalter
*/
public static ProcessCreateResponse handleServlet(
HttpServletRequest request, ServletContext context) {
ProcessCreateResponse response = new ProcessCreateResponse(context);
FormItemList items = null;
try {
items = FormItemList.extractFormItems(request, factory);
} catch (FileUploadException e) {
e.printStackTrace();
}
// items is == null, when request Content-Type is not multipart
if (items == null) {
response.addHttpRequestError(CreateStatusCodes.REQUEST_MUST_BE_MULTIPART);
return response;
}
return checkRequestParameter(items, response, context);
}
示例6: initFields
import org.apache.commons.fileupload.FileUploadException; //導入方法依賴的package包/類
/**
* 處理上傳內容
*
* @param request
* @param maxSize
* @return
*/
// @SuppressWarnings("unchecked")
private Map<String, Object> initFields(HttpServletRequest request) {
// 存儲表單字段和非表單字段
Map<String, Object> map = new HashMap<String, Object>();
// 第一步:判斷request
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
// 第二步:解析request
if (isMultipart) {
// Create a factory for disk-based file items
DiskFileItemFactory factory = new DiskFileItemFactory();
// 閥值,超過這個值才會寫到臨時目錄,否則在內存中
factory.setSizeThreshold(1024 * 1024 * 10);
factory.setRepository(new File(tempPath));
// Create a new file upload handler
ServletFileUpload upload = new ServletFileUpload(factory);
upload.setHeaderEncoding("UTF-8");
// 最大上傳限製
upload.setSizeMax(maxSize);
/* FileItem */
List<FileItem> items = null;
// Parse the request
try {
items = upload.parseRequest(request);
} catch (FileUploadException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// 第3步:處理uploaded items
if (items != null && items.size() > 0) {
Iterator<FileItem> iter = items.iterator();
// 文件域對象
List<FileItem> list = new ArrayList<FileItem>();
// 表單字段
Map<String, String> fields = new HashMap<String, String>();
while (iter.hasNext()) {
FileItem item = iter.next();
// 處理所有表單元素和文件域表單元素
if (item.isFormField()) { // 表單元素
String name = item.getFieldName();
String value = item.getString();
fields.put(name, value);
} else { // 文件域表單元素
list.add(item);
}
}
map.put(FORM_FIELDS, fields);
map.put(FILE_FIELDS, list);
}
}
return map;
}
示例7: doPost
import org.apache.commons.fileupload.FileUploadException; //導入方法依賴的package包/類
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
try {
List<FileItem> items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request);
String fileName = null;
String filePath = null;
String path = null;
InputStream fileContent = null;
for (FileItem item : items) {
if (!item.isFormField()) {
fileContent = item.getInputStream();
fileName = FilenameUtils.getName(item.getName());
}else if (item.isFormField() && item.getFieldName() != null
&& item.getFieldName().equals("filePath")){
path = item.getString();
}
}
filePath = path + File.separator + fileName;
OutputStream dest = new FileOutputStream(new
File(filePath));
int read = 0;
byte[] bytes = new byte[1024];
while ((read = fileContent.read(bytes)) != -1) {
dest.write(bytes, 0, read);
}
fileContent.close();
dest.close();
} catch (FileUploadException e) {
e.printStackTrace();
throw new ServletException("Cannot parse multipart request.", e);
}
index(request, response);
}
示例8: execute
import org.apache.commons.fileupload.FileUploadException; //導入方法依賴的package包/類
public boolean execute(HttpServletRequest request, HttpServletResponse response)
throws CarbonException, IOException {
try {
return super.executeCommon(request, response);
} catch (FileUploadException e) {
e.printStackTrace(); //Todo: change body of catch statement use File | Settings | File Templates.
}
return false;
}
示例9: processRequest
import org.apache.commons.fileupload.FileUploadException; //導入方法依賴的package包/類
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws IOException {
Path batchDir = storageBean.createBatchDirectory();
ServletFileUpload servletFileUpload = new ServletFileUpload(new DiskFileItemFactory());
List<FileItem> items;
try {
items = servletFileUpload.parseRequest(request);
} catch (FileUploadException e) {
response.sendError(500, e.getMessage());
e.printStackTrace();
return;
}
for (FileItem item : items) {
// process files (ignore regular form fields)
if (!item.isFormField()) {
String fileName = FilenameUtils.getName(item.getName());
InputStream fileContent = item.getInputStream();
storageBean.storeToDirectory(fileContent, fileName, batchDir);
}
}
Path infoProps = Paths.get(batchDir.toString(), DirectoryLoader.infoFileName);
if (!Files.exists(infoProps)) { // if the info file wasn't uploaded, generate a random demo one
Properties demo = Main.createDemoProperties();
Path props = Paths.get(batchDir.toString(), DirectoryLoader.infoFileName);
demo.store(Files.newOutputStream(props), "Demo properties");
}
}
示例10: doPost
import org.apache.commons.fileupload.FileUploadException; //導入方法依賴的package包/類
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
boolean isMultipart = ServletFileUpload.isMultipartContent(req);
HttpSession session = req.getSession(false);
Integer userId = (int)session.getAttribute("id_user");
Integer orderId = (int)session.getAttribute("currentOrder");
PrintWriter out = resp.getWriter();
JsonObject jsonObject = new JsonObject();
if(isMultipart && userId != -1 && orderId != -1){
// Create a factory for disk-based file items
DiskFileItemFactory factory = new DiskFileItemFactory();
// Configure a repository (to ensure a secure temp location is used)
ServletContext servletContext = this.getServletConfig().getServletContext();
FileCleaningTracker tracker = FileCleanerCleanup.getFileCleaningTracker(servletContext);
factory.setFileCleaningTracker(tracker);
File repository = (File) servletContext.getAttribute("javax.servlet.context.tempdir");
factory.setRepository(repository);
// Create a new file upload handler
ServletFileUpload upload = new ServletFileUpload(factory);
try {
List<FileItem> items = upload.parseRequest(req);
for (FileItem imageFile : items){
byte[] imageByte = imageFile.get();
Order order = new Order();
order.setId(orderId);
Image image = new Image();
image.setDataimage(imageByte);
image.setOrder(order);
new ImageDBManager().create(image);
}
jsonObject.addProperty("success", true);
} catch (FileUploadException e) {
jsonObject.addProperty("success", false);
e.printStackTrace();
}
} else {
jsonObject.addProperty("success", false);
}
out.append(jsonObject.toString());
out.flush();
}
示例11: initFields
import org.apache.commons.fileupload.FileUploadException; //導入方法依賴的package包/類
/**
* 處理上傳內容
*
* @param request
* @param maxSize
* @return
*/
// @SuppressWarnings("unchecked")
private Map<String, Object> initFields(HttpServletRequest request) {
// 存儲表單字段和非表單字段
Map<String, Object> map = new HashMap<String, Object>();
// 第一步:判斷request
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
// 第二步:解析request
if (isMultipart) {
// Create a factory for disk-based file items
DiskFileItemFactory factory = new DiskFileItemFactory();
// 閥值,超過這個值才會寫到臨時目錄,否則在內存中
factory.setSizeThreshold(1024 * 1024 * 10);
factory.setRepository(new File(tempPath));
// Create a new file upload handler
ServletFileUpload upload = new ServletFileUpload(factory);
upload.setHeaderEncoding("UTF-8");
// 最大上傳限製
upload.setSizeMax(maxSize);
/* FileItem */
List<FileItem> items = null;
// Parse the request
try {
items = upload.parseRequest(request);
} catch (FileUploadException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// 第3步:處理uploaded items
if (items != null && items.size() > 0) {
Iterator<FileItem> iter = items.iterator();
// 文件域對象
List<FileItem> list = new ArrayList<FileItem>();
// 表單字段
Map<String, String> fields = new HashMap<String, String>();
while (iter.hasNext()) {
FileItem item = iter.next();
// 處理所有表單元素和文件域表單元素
if (item.isFormField()) { // 表單元素
String name = item.getFieldName();
String value = item.getString();
fields.put(name, value);
} else { // 文件域表單元素
list.add(item);
}
}
map.put(FORM_FIELDS, fields);
map.put(FILE_FIELDS, list);
}
}
return map;
}
示例12: processRequest
import org.apache.commons.fileupload.FileUploadException; //導入方法依賴的package包/類
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
if (isMultipart) {
ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory());
try {
List items = upload.parseRequest(request);
Iterator iter = items.iterator();
while (iter.hasNext()) {
FileItem item = (FileItem) iter.next();
if (!item.isFormField()) {
String targetUrl = Config.getConfigProperty(ConfigurationEnum.DIGITAL_MEDIA);
if (StringUtils.isBlank(targetUrl)) {
targetUrl = request.getRequestURL().toString();
targetUrl = targetUrl.substring(0, targetUrl.lastIndexOf('/'));
}
targetUrl += "/DigitalMediaController";
PostMethod filePost = new PostMethod(targetUrl);
filePost.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, false);
UploadPartSource src = new UploadPartSource(item.getName(), item.getSize(), item.getInputStream());
Part[] parts = new Part[1];
parts[0] = new FilePart(item.getName(), src, item.getContentType(), null);
filePost.setRequestEntity(new MultipartRequestEntity(parts, filePost.getParams()));
HttpClient client = new HttpClient();
client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
int status = client.executeMethod(filePost);
if (status == HttpStatus.SC_OK) {
String data = filePost.getResponseBodyAsString();
JSONObject json = new JSONObject(data);
if (json.has("id")) {
JSONObject responseJson = new JSONObject();
responseJson.put("success", true);
responseJson.put("id", json.getString("id"));
responseJson.put("uri", targetUrl + "?id=" + json.getString("id"));
response.getWriter().write(responseJson.toString());
}
}
filePost.releaseConnection();
return;
}
}
} catch (FileUploadException e) {
e.printStackTrace();
} catch (JSONException je) {
je.printStackTrace();
}
}
response.getWriter().write("{success: false}");
}
示例13: doPost
import org.apache.commons.fileupload.FileUploadException; //導入方法依賴的package包/類
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, java.io.IOException {
logger.warn("doPost Servlet call");
System.out.println("doPost Servlet call");
// Check that we have a file upload request
isMultipart = ServletFileUpload.isMultipartContent(request);
ServletFileUpload upload = new ServletFileUpload();
try {
FileItemIterator iterator = upload.getItemIterator(request);
String itemId = "";
while (iterator.hasNext()) {
FileItemStream item = iterator.next();
InputStream stream = item.openStream();
if ( item.isFormField() ) {
System.out.println("ContentType: " + item.getContentType());
System.out.println("Form field : " + item.getFieldName() );
// parse the field with itemId
if ( item.getFieldName().equals("itemId") ) {
//
BufferedReader reader = new BufferedReader(new InputStreamReader(item.openStream()));
StringBuffer res = new StringBuffer();
String line;
while ((line = reader.readLine()) != null) {
res.append(line);
}
reader.close();
System.out.println("imageId: " + res);
itemId = res.toString();
//
// JSONObject jsonObj = new JSONObject(res);
// String count = jsonObj.getInt("count");
// System.out.println("-#: " + data);
}
} else {
System.out.println("Got an uploaded file: " + item.getFieldName() + ", name = " + item.getName()+ " content="+item.getContentType() + " header="+item.getHeaders());
byte[] bytes = IOUtils.toByteArray(stream);
System.out.println("File length: " + bytes.length);
System.out.println("ItemId : " + itemId);
// Create image and store image in datastore
Image image = new Image(item.getName(), new Blob( bytes));
Key<Image> key = ObjectifyService.ofy().save().entity(image).now();
// get ImageId from the instance (not needed)
// Long imageId = image.getImageId();
// Key<Image> imageKey = Key.create(Image.class, Long.parseLong(imageId.toString()));
Ref<Image> imageRef = Ref.create(key);
//
Item item1 = ObjectifyService.ofy().load().type(Item.class).id(Long.parseLong(itemId)).now();
item1.addImage(imageRef); //item1.addImage(Ref.create(imageRef));
ObjectifyService.ofy().save().entity(item1).now();
}
}
} catch (FileUploadException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
} catch (Exception ex) {
System.out.println(ex);
}
}
示例14: doPost
import org.apache.commons.fileupload.FileUploadException; //導入方法依賴的package包/類
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("Hello<br/>");
boolean isMultipartContent = ServletFileUpload.isMultipartContent(request);
if (!isMultipartContent) {
out.println("You are not trying to upload<br/>");
return;
}
out.println("You are trying to upload<br/>");
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
// upload.setSizeMax(MAX_UPLOAD_IN_MEGS * 1024 * 1024);
ProgressListener testProgressListener = new ProgressListener();
upload.setProgressListener(testProgressListener);
HttpSession session = request.getSession();
session.setAttribute("testProgressListener", testProgressListener);
try {
List<FileItem> fields = upload.parseRequest(request);
out.println("Number of fields: " + fields.size() + "<br/><br/>");
Iterator<FileItem> it = fields.iterator();
if (!it.hasNext()) {
out.println("No fields found");
return;
}
out.println("<table border=\"1\">");
while (it.hasNext()) {
out.println("<tr>");
FileItem fileItem = it.next();
boolean isFormField = fileItem.isFormField();
if (isFormField) {
out.println("<td>regular form field</td><td>FIELD NAME: " + fileItem.getFieldName() +
"<br/>STRING: " + fileItem.getString()
);
out.println("</td>");
} else {
out.println("<td>file form field</td><td>FIELD NAME: " + fileItem.getFieldName() +
// "<br/>STRING: " + fileItem.getString() +
"<br/>NAME: " + fileItem.getName() +
"<br/>CONTENT TYPE: " + fileItem.getContentType() +
"<br/>SIZE (BYTES): " + fileItem.getSize() +
"<br/>TO STRING: " + fileItem.toString()
);
out.println("</td>");
}
out.println("</tr>");
}
out.println("</table>");
} catch (FileUploadException e) {
out.println("Error: " + e.getMessage());
e.printStackTrace();
}
}