JSP-文件上传 [英] JSP - File Uploading

查看:64
本文介绍了JSP-文件上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

教程用于文件上传.我复制了代码并将其保存到我的项目中.我更改

String filePath = context.getInitParameter("file-upload");

进入

String filePath = context.getInitParameter("uploads");

因为我想将图像保存在名为uploads的文件夹中.该文件夹位于我放置脚本的文件夹之外.我什至尝试过

String filePath = context.getInitParameter("../uploads");

但是在输出代码中

out.println("Uploaded Filename: " + filePath + fileName + "<br>");

FilePath为null,并且文件夹中没有图像.如何正确设置filePath?

解决方案

您也可以将目录详细信息存储在属性文件中-

catalina.properties中的存储值如下(该文件位于$CATALINA_HOME/conf/catalina.properties)

my.home=directory/path

(WEB-INF/web.xml)

<context-param>
<param-name>uploads</param-name>
<param-value>${my.home}</param-value>
</context-param>

然后尝试

String filePath = context.getInitParameter("uploads");

Tutorials for File Uploading. I copied the code and saved it my project. I change the

String filePath = context.getInitParameter("file-upload");

into

String filePath = context.getInitParameter("uploads");

Because I want to save the image in the folder named uploads. This folder is located outside the folder where I have put the script. I even tried

String filePath = context.getInitParameter("../uploads");

But in the output code

out.println("Uploaded Filename: " + filePath + fileName + "<br>");

FilePath is null and there is no image in the folder. How to properly set the filePath?

解决方案

You can store directory details in properties file as well--

in catalina.properties store values like below(this file is located at $CATALINA_HOME/conf/catalina.properties)

my.home=directory/path

(WEB-INF/web.xml)

<context-param>
<param-name>uploads</param-name>
<param-value>${my.home}</param-value>
</context-param>

and then try

String filePath = context.getInitParameter("uploads");

这篇关于JSP-文件上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆