作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有jsp代码
college.jsp页面
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<html>
<head>
</head>
<body>
<html:form action ="/college.do">
<fieldset>
<legend>COLLEGE INFORMATION :</legend>
<pre>
Gallery Images: <input type="file" name="file[]" multiple/>
<html:submit value = "S U B M I T"/>
</fieldset>
</html:form>
</body>
</html>
如何在struts中上传多张图片
项目中存储文件夹的图像总数
使用这个jsp,但我想要 CollegeAction 类和 CollegeForm 类如何做到这一点请帮我编码
最佳答案
你可能想做这样的事情。在您的 jsp 文件中
<html:file property="image1"/>
<html:file property="image2"/>
<html:file property="image3"/>
不要忘记设置 html 表单的属性 enctype="multipart/form-data"
然后在您的 Form
文件中创建图像变量:
private FormFile image1;
private FormFile image2;
private FormFile image3;
..以及它们的 getter 和 setter。
然后您可以使用这些变量在服务器端创建图像:
OutputStream bos = null;
InputStream stream = null;
try {
String fileName = form.getImage().getFileName();
String directory = "C:/your_folder";
File f = new File(directory);
if (!f.exists()) {
f.mkdir();
if (!"".equals(fileName)) {
stream = form.getImage1().getInputStream();
bos = new FileOutputStream(directory + fileName);
int bytesRead = 0;
byte[] buffer = new byte[8192];
while ((bytesRead = stream.read(buffer, 0, 8192)) != -1) {
bos.write(buffer, 0, bytesRead);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
关于java - java(struts)中如何使用jsp上传多张图片?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12103702/
我有以下正则表达式 /[a-zA-Z0-9_-]/ 当字符串只包含从 a 到z 大小写、数字、_ 和 -。 我的代码有什么问题? 能否请您向我提供一个简短的解释和有关如何修复它的代码示例? //var
我是一名优秀的程序员,十分优秀!