public class LedgerAdd extends BaseAction {
protected ActionForward executeAction(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
DynaActionForm LedgerForm = (DynaActionForm) form;
if (LedgerForm != null) {
FormFile file = (FormFile) LedgerForm.get("photo");
if (file != null) {
String contentType = file.getContentType();
String size = (file.getFileSize() + "bytes");
String fileUrl = file.getFileName();
int s_id = fileUrl.lastIndexOf(".");
String ext = fileUrl.substring(s_id);
String nuclideName = (String) LedgerForm.get("nuclideName")
String ratify = "2";
if (nuclideName != null && !nuclideName.equals("")
&& fileUrl != null && !fileUrl.equals("")) {
Date d = new Date();
java.text.SimpleDateFormat df = new java.text.SimpleDateFormat();
Calendar calendar = GregorianCalendar.getInstance();
df.applyPattern("yyyyMMddHHmmss");
InputStream stream = file.getInputStream();// 把文件读入
String path=request.getSession().getServletContext().getRealPath("/");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
OutputStream bos = new FileOutputStream(path+ "/UploadFile/" + df.format(d) + ext);
int bytesRead = 0;
byte[] buffer = new byte[8192];
while ((bytesRead = stream.read(buffer, 0, 8192)) != -1) {
bos.write(buffer, 0, bytesRead);// 将文件写入服务器 }
bos.close();stream.close();
int addid = rs.addLedger(request.getContextPath()+ "/UploadFile/" + df.format(d) + ext,nuclideName, remark);
if (addid > 0) {
request.setAttribute("msg", "添加成功");} else {
request.setAttribute("msg", "添加失败");}} else {
request.setAttribute("msg", "带*的参数必须输入");}}}
return mapping.findForward("success");}}
图片上传 tomcat重新部署后图片被删除请问要如何解决
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
8条回答
- AngelAndAngel 2011-08-24 09:12关注
我 传到哪里啊 给地址一下给我 我给你做了一个
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
- ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
- ¥15 乘性高斯噪声在深度学习网络中的应用
- ¥15 运筹学排序问题中的在线排序
- ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
- ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
- ¥15 C++ 头文件/宏冲突问题解决
- ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
- ¥50 安卓adb backup备份子用户应用数据失败
- ¥20 有人能用聚类分析帮我分析一下文本内容嘛