Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to upload Files from scratch by Flex2.0

2025-03-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces how to upload files from scratch with Flex2.0. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.

Flex2.0 implements file upload from scratch

I've done it before in Flex1.5, but I used oreilly's cos.jar. And when Flex1.5, there is no direct reference to the FileReference class in as, so you can only write an uploaded as file and compile it into a swf file, and then load the swf file to upload.

Flex2.0Release then uploaded it with oreilly's upload package, which was a success. So go back to apache's common-fileupload-1.1.1 to study upload. Finally came to fruition. Coupled with the fact that I have been walking around various forums, I found that many workers are interested in uploading files on Flex2.0. So I decided to take some time to share my achievements with you.

1. Aside from the installation and configuration of the environment, it can be found in many places on the Internet. (mine is: JDK1.4.2,FlexBuilder2,Flex2SDK,Tomcat4.1,Eclips3.0.1, but it is said that now Flex2.0 needs to install JDK1.5 to use RemoteObject).

2. First create a tomcat project in Eclips, for example, name it FileUpload.

3. Find the FlexSDK installation directory and copy the flex.war and rename it to flex.rar. Untie this bag. Copy the META-INF and WEB-INF folder inside to the working directory of Eclips (mine: d:workspaces)-under the FileUpload directory you just created.

Create a new project under 4.FlexBuilder2.

5. Introduce common-fileupload-1.1.1.jar and common-io-1.2.jar into the project (if not, go to http://www.apache.org to download).

6. Write the upload servletmyUpload.java code as follows (the path for uploading files is: d:upload):

Packagecom.fileupload; importjava.io.File; importjava.io.IOException; importjava.util.Iterator; importjava.util.List;importjavax.servlet. ServletException; importjavax.servlet.http.HttpServlet; importjavax.servlet.http.HttpServletRequest; importjavax.servlet.http.HttpServletResponse; importorg.apache.commons.fileupload.FileItem; importorg.apache.commons.fileupload.FileUploadException; importorg.apache.commons.fileupload.disk. DiskFileItemFactory; importorg.apache.commons.fileupload.servlet. ServletFileUpload; publicclassmyUploadextendsHttpServlet {privateStringuploadPath= "D:\\ upload\"; privateintmaxPostSize=100*1024*1024; publicvoiddoPost (HttpServletRequestreq,HttpServletResponseres) throwsServletException,IOException {res.setContentType ("text/html;charset=UTF-8"); DiskFileItemFactoryfactory=newDiskFileItemFactory (); factory.setSizeThreshold (4096); ServletFileUploadupload=newServletFileUpload (factory); upload.setSizeMax (maxPostSize); try {ListfileItems=upload.parseRequest (req); Iteratoriter=fileItems.iterator (); while (iter.hasNext ()) {FileItemitem= (FileItem) iter.next () If (! item.isFormField ()) {Stringname=item.getName (); try {item.write (newFile (uploadPath+name));} catch (Exceptione) {e.printStackTrace ();} catch (FileUploadExceptione) {e.printStackTrace ();}

Stored in.. / src/com/fileupload

7. Add the following code to web.xml. (used to call servlet)

MyUpload FileUploadServlet FileServletExample com.fileupload.myUpload myUpload / myUpload

8. The FileUpload.mxml file code of the foreground is as follows:

9. Open tomcat and run. The great task has been completed!

About how Flex2.0 from scratch to achieve file upload to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report