`
- 浏览:
55142 次
- 性别:
- 来自:
湖北武汉
-
servlet中测试成功:
java 代码
- String filesystempath = request.getSession().getServletContext().getRealPath("/");
- ServletRequestContext srcontext = new ServletRequestContext(request);
- System.out.println(srcontext.getCharacterEncoding());
- System.out.println(srcontext.getContentType());
- boolean isMultipart = ServletFileUpload.isMultipartContent(request);
- if (isMultipart) {
- ServletFileUpload upload = new ServletFileUpload();
- try {
-
- FileItemIterator iter = upload.getItemIterator(request);
- while (iter.hasNext()) {
- FileItemStream item = iter.next();
- //System.out.println(item.getContentType());
- InputStream stream = item.openStream();
- if (item.isFormField()) {
-
- } else {
-
- String clientrealpath = item.getName();
- clientrealpath = clientrealpath.replace("\\", "\\\\");
-
- String filename = StringHelper.getFileName(clientrealpath);
-
- File newfile = new File(filesystempath+filename);
- OutputStream os =new FileOutputStream(newfile);
- byte[] b = new byte[8192];
- int len;
- while ((len = stream.read(b)) != -1) {
- os.write(b, 0, len);
- os.flush();
- os.close();
- stream.close();
-
- }
- }
- } catch (FileUploadException e) {
- e.printStackTrace();
- }
- }
分享到:
Global site tag (gtag.js) - Google Analytics
相关推荐
-下载后解压zip包,将commons-fileupload-1.1.1.jar,和commons-io-1.2.jar(这里我们用的是更新的版本,但是用法是一样的)复制到tomcat的webapps\你的webapp\WEB-INF\lib\下,如果目录不存在请自建目录。 新建一个...
此时,打开选择框,我们选择默认的【copy files】,点击【OK】关闭。然后我们就可以在lib文件夹下看到我们复制成功的jar包。 4、此时,只是把jar包复制到项目中,还不能使用。我们再在项目名上右击,依次选择...
9.4.3. Basic Zend_Date Operations Common to Many Date Parts 9.4.3.1. List of Date Parts 9.4.3.2. List of Date Operations 9.4.4. Comparing Dates 9.4.5. Getting Dates and Date Parts 9.4.6. Working ...
# Remember to upload all the language files and template files to all your # language packs and template directories # # If you use FTP please remember to use ASCII mode for text files (*.php, *.tpl) ...
To use the JavaMail 1.2 API, download the JavaMail 1.2 implementation, unbundle the javamail-1_2.zip file, and add the mail.jar file to your CLASSPATH. The 1.2 implementation comes with an SMTP, ...
$a = 1.2e3; # 双精度数的指数形式 字符串 字符串可以由单引号或双引号引出的字段定义。注意不同的是被单引号引出的字符串是以字面定义的,而双引号引出的字符串可以被扩展。反斜杠(\)可以被用来分割某些...