Dwr file upload and dwr2 File Upload

Source: Internet
Author: User

Dwr file upload and dwr2 File Upload

Configure FileService service ing:

Dwr. xml

<create creator="new">      <param name="class" value="com.demo.service.FileService"/>    </create>


FileService:

package com.demo.service;import java.io.File;import java.io.IOException;import java.io.InputStream;import org.apache.commons.io.FileUtils;import org.apache.commons.io.FilenameUtils;import org.directwebremoting.WebContext;import org.directwebremoting.WebContextFactory;public class FileService {public String upload(InputStream inputStream,String fileName) throws IOException{String tempFileName=FilenameUtils.getName(fileName);String path=getRealPath("upload");File file=new File(path+File.separator+tempFileName);FileUtils.copyInputStreamToFile(inputStream, file);return file.getPath();}public String getRealPath(String dir){WebContext context=WebContextFactory.get();return context.getSession().getServletContext().getRealPath(dir);}}


Upload. jsp:

<% @ Page language = "java" contentType = "text/html; charset = UTF-8" pageEncoding = "UTF-8" %> <! DOCTYPE html PUBLIC "-// W3C // dtd html 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd"> 
 

Result:

The attachment has been uploaded to the upload folder.




Dwr + ajax for File Upload

After a file is selected, there will be a file address. You can upload this parameter to the background through AJAX to let the background file. length ()
The method returns the length ~

Dwr Image Upload

I wrote a website using dwr and tested it on the local machine. However, once uploaded to the java space, I said IE was dizzy, which was caused by unspecified file names. <Script type = "text/javascript" src ="
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.