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 use SWFupload in servlet

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article will explain in detail how to use SWFupload in servlet. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

1. It is a null problem to send parameters to the background and receive Chinese in the background.

Configure in initialization parameters

Use_query_string: true,// (as if this is necessary or parameters will not be received at the backend) true means to pass to the server in get mode, and false means to pass it in post mode

For example, the initialization parameters are configured as follows

Post_params: {"name": encodeURIComponent ("pockmarked"), / / encode it in Chinese (as if it is the only way to be received by servlet otherwise it is null), rest assured that it will be decoded on the server side.

"hello": ""

}

Server-side reception (java code):

Response.setContentType ("text/html;charset=UTF-8")

DiskFileItemFactory factory = new DiskFileItemFactory ()

ServletFileUpload upload = new ServletFileUpload (factory); / / Factory class prepared to receive uploaded files

String ss=request.getParameter ("name"); / / receives the parameters in post_params, which seems to be the only way to receive them.

String names=java.net.URLDecoder.decode (ss, "UTF-8"); / / decode the previously encoded string

Upload.setHeaderEncoding ("utf-8"); / / solve the problem of garbled codes for uploaded files

Try {

List items = upload.parseRequest (request)

Iterator iter = items.iterator ()

While (iter.hasNext ()) {

FileItem item = (FileItem) iter.next ()

If (! item.isFormField ()) {/ / is not a form field, which means uploading files

String fieldName = item.getFieldName (); / / the value of the name attribute in the file domain

String fileName = item.getName (); / / File name

String contentType = item.getContentType (); / / File type

Long size = item.getSize (); / / size of the file in bytes

File saveFile = new File ("D:/test/" + fileName); / / define a file to point to a specific file (folder on disk D)

Item.write (saveFile); / / write the uploaded content to a file

}

}

} catch (Exception e) {

/ / TODO Auto-generated catch block

E.printStackTrace ()

System.out.println ("File upload was not successful!")

} / / resolve request request

This is the end of the article on "how to use SWFupload in servlet". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please 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

Servers

Wechat

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

12
Report