点击确定的时候执行的修改操作,但是把file下以前存的都覆盖掉了,,怎么解决,求高手指点<%
ProductSu ps = new ProductSu();
IProductSuManager productSuMgr = ProductSuPeer.getInstance();
boolean error = true;
String filename = ""; boolean doCreate = ParamUtil.getBooleanParameter(request, "doCreate");
if (doCreate) {
com.bizwink.cms.kings.jspsmart.upload.File tmpFile = null;
try {
//实例化上载bean
SmartUpload mySmartUpload = new SmartUpload();
//初始化
mySmartUpload.initialize(pageContext);
//设置上载的最大值
mySmartUpload.setMaxFileSize(50 * 1024 * 1024);
try {
//上载文件
mySmartUpload.upload();
} catch (Exception e) {
response.sendRedirect("edit.jsp");
}
id = Integer.parseInt(mySmartUpload.getRequest().getParameter("id"));
startflag = Integer.parseInt(mySmartUpload.getRequest().getParameter("startflag"));
productname = mySmartUpload.getRequest().getParameter("productname");
safestock = Integer.parseInt(mySmartUpload.getRequest().getParameter("safestock"));
lastpurchasedate = mySmartUpload.getRequest().getParameter("lastpurchasedate");
lastdeliverydate = mySmartUpload.getRequest().getParameter("lastdeliverydate");
quantity = Integer.parseInt(mySmartUpload.getRequest().getParameter("quantity"));
Files uploadFiles = mySmartUpload.getFiles();
for (int i = 0; i < mySmartUpload.getFiles().getCount(); i++) {
File tempFile = mySmartUpload.getFiles().getFile(i);
if (!tempFile.isMissing()) {
filename = tempFile.getFileName();
System.out.println("tmf = " + tempFile.isMissing());
String ext = tempFile.getFileExt(); String newfilename = String.valueOf(System.currentTimeMillis()) + "_" + i + "." + ext;
if (i == 0) {
maxpicture = newfilename;
}
if (i == 1) {
minpicture = newfilename;
}
if (i == 2) {
specificpicture = newfilename;
}
if (i == 3) {
picture = newfilename;
}
if (i == 4) {
titlepicture = newfilename;
}
if (i == 5) {
borntitlepicture = newfilename;
}
String uploadPath = application.getRealPath("/") + java.io.File.separator + "productpic" + java.io.File.separator;
java.io.File file = new java.io.File(uploadPath);
if (!file.exists()) {
file.mkdirs();
} boolean flag = tempFile.saveAs(uploadPath + newfilename);
} }
mySmartUpload.stop();
} catch (Exception
e) {
System.out.println(e.toString()); error = true;
} if (startflag == 1) {
ps.setPicture(picture);
ps.setTitlePicture(titlepicture);
ps.setBornTitlePicture(borntitlepicture);
ps.setSiteid(siteid);
productSuMgr.updateProductSu(ps, id);
response.sendRedirect("product.jsp");
}
}
ps = productSuMgr.getByIdproduct(id);
%>
<HTML>
<HEAD><TITLE>修改商品信息</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<LINK href="../images/common.css" type=text/css rel=stylesheet>
<LINK href="../images/forum.css" type=text/css rel=stylesheet>
<SCRIPT language=javascript>
function check()
{
if (form1.productname.value == "")
{
alert("请输入商品名称!");
return false;
}
return true;
}
function goto()
{
form1.action = "product.jsp";
form1.submit();
}
</SCRIPT> <META content="MSHTML 6.00.2800.1479" name=GENERATOR>
</HEAD>
<BODY bgColor=#ffffff>
<FORM name=form1 action=edit.jsp?doCreate=true method=post enctype="multipart/form-data">
<INPUT type=hidden value=1 name=startflag>
<input type=hidden name="id" value="<%=id%>"> <CENTER>
<TABLE cellSpacing=0 borderColorDark=#ffffff cellPadding=0 width=80%
borderColorLight=#008000 border=1 enctype="multipart/form-data">
<TBODY>
<TR>
<TD bgColor=#33ccff colSpan=2 height=32>
<P align=center>修改商品信息</P></TD>
</TR>
<TD align=right>大图片:</TD>
<TD align=left> <% if (ps.getMaxPicture() != null) { %>
<img src="<%="../../../"+"productpic" + "\\" +ps.getMaxPicture()%>" height="25"
width="50"><% } else { %>
--<% } %> <INPUT type="file" size=45 name=maxpicture value="" onpropertychange="f(this)">
</TD>
</TR>
<TR height=32>
<TD align=right>小图片:</TD>
<TD align=left> <% if (ps.getMinPicture() != null) { %>
<img src="<%="../../../"+"productpic" + "\\" +ps.getMinPicture()%>" height="25"
width="50"><% } else { %>
--<% } %> <INPUT type="file" size=45 name=minpicture value="" onpropertychange="f(this)"></TD>
</TR>
<TR height=32>
<TD align=right>特效图:</TD>
<TD align=left> <% if (ps.getSpecificPicture() != null) { %>
<img src="<%="../../../"+"productpic" + "\\" +ps.getSpecificPicture()%>" height="25"
width="50"><% } else { %>
--<% } %> <INPUT type="file" size=45 name=specificpicture value="" onpropertychange="f(this)">
</TD>
</TR>
<TR height=32>
<TD align=right>原图:</TD>
<TD align=left> <% if (ps.getPicture() != null) { %>
<img src="<%="../../../"+"productpic" + "\\" +ps.getPicture()%>" height="25"
width="50"><% } else { %>
--<% } %> <INPUT type="file" size=45 name=picture value="" onpropertychange="f(this)"></TD>
</TR>
<TR height=32>
<TD align=right>标题图:</TD>
<TD align=left> <% if (ps.getTitlePicture() != null) { %>
<img src="<%="../../../"+"productpic" + "\\" +ps.getTitlePicture()%>" height="25"
width="50"><% } else { %>
--<% } %> <INPUT type="file" size=45 name=titlepicture value="" onpropertychange="f(this)">
</TD>
</TR>
<TR height=32>
<TD align=right>原标题图:</TD>
<TD align=left> <% if (ps.getBornTitlePicture() != null) { %>
<img src="<%="../../../"+"productpic" + "\\" +ps.getBornTitlePicture()%>" height="25"
width="50"><% } else { %>
--<% } %> <INPUT type="file" size=45 name=borntitelpicture value="" onpropertychange="f(this)">
</TD>
</TR>
<TR height=32>
<TD colSpan=2><FONT
color=red> 注:带有*的项为必填项</FONT></TD>
</TR>
</TBODY>
</TABLE>
<P align=center><INPUT onclick="javascript:return check();" type=submit value=" 确 认 " name=Ok>
<INPUT onclick=javascript:goto(); type=button value=返回列表 name=golist>
</P>
</CENTER>
</FORM>
</BODY>
</HTML>
ProductSu ps = new ProductSu();
IProductSuManager productSuMgr = ProductSuPeer.getInstance();
boolean error = true;
String filename = ""; boolean doCreate = ParamUtil.getBooleanParameter(request, "doCreate");
if (doCreate) {
com.bizwink.cms.kings.jspsmart.upload.File tmpFile = null;
try {
//实例化上载bean
SmartUpload mySmartUpload = new SmartUpload();
//初始化
mySmartUpload.initialize(pageContext);
//设置上载的最大值
mySmartUpload.setMaxFileSize(50 * 1024 * 1024);
try {
//上载文件
mySmartUpload.upload();
} catch (Exception e) {
response.sendRedirect("edit.jsp");
}
id = Integer.parseInt(mySmartUpload.getRequest().getParameter("id"));
startflag = Integer.parseInt(mySmartUpload.getRequest().getParameter("startflag"));
productname = mySmartUpload.getRequest().getParameter("productname");
safestock = Integer.parseInt(mySmartUpload.getRequest().getParameter("safestock"));
lastpurchasedate = mySmartUpload.getRequest().getParameter("lastpurchasedate");
lastdeliverydate = mySmartUpload.getRequest().getParameter("lastdeliverydate");
quantity = Integer.parseInt(mySmartUpload.getRequest().getParameter("quantity"));
Files uploadFiles = mySmartUpload.getFiles();
for (int i = 0; i < mySmartUpload.getFiles().getCount(); i++) {
File tempFile = mySmartUpload.getFiles().getFile(i);
if (!tempFile.isMissing()) {
filename = tempFile.getFileName();
System.out.println("tmf = " + tempFile.isMissing());
String ext = tempFile.getFileExt(); String newfilename = String.valueOf(System.currentTimeMillis()) + "_" + i + "." + ext;
if (i == 0) {
maxpicture = newfilename;
}
if (i == 1) {
minpicture = newfilename;
}
if (i == 2) {
specificpicture = newfilename;
}
if (i == 3) {
picture = newfilename;
}
if (i == 4) {
titlepicture = newfilename;
}
if (i == 5) {
borntitlepicture = newfilename;
}
String uploadPath = application.getRealPath("/") + java.io.File.separator + "productpic" + java.io.File.separator;
java.io.File file = new java.io.File(uploadPath);
if (!file.exists()) {
file.mkdirs();
} boolean flag = tempFile.saveAs(uploadPath + newfilename);
} }
mySmartUpload.stop();
} catch (Exception
e) {
System.out.println(e.toString()); error = true;
} if (startflag == 1) {
ps.setPicture(picture);
ps.setTitlePicture(titlepicture);
ps.setBornTitlePicture(borntitlepicture);
ps.setSiteid(siteid);
productSuMgr.updateProductSu(ps, id);
response.sendRedirect("product.jsp");
}
}
ps = productSuMgr.getByIdproduct(id);
%>
<HTML>
<HEAD><TITLE>修改商品信息</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<LINK href="../images/common.css" type=text/css rel=stylesheet>
<LINK href="../images/forum.css" type=text/css rel=stylesheet>
<SCRIPT language=javascript>
function check()
{
if (form1.productname.value == "")
{
alert("请输入商品名称!");
return false;
}
return true;
}
function goto()
{
form1.action = "product.jsp";
form1.submit();
}
</SCRIPT> <META content="MSHTML 6.00.2800.1479" name=GENERATOR>
</HEAD>
<BODY bgColor=#ffffff>
<FORM name=form1 action=edit.jsp?doCreate=true method=post enctype="multipart/form-data">
<INPUT type=hidden value=1 name=startflag>
<input type=hidden name="id" value="<%=id%>"> <CENTER>
<TABLE cellSpacing=0 borderColorDark=#ffffff cellPadding=0 width=80%
borderColorLight=#008000 border=1 enctype="multipart/form-data">
<TBODY>
<TR>
<TD bgColor=#33ccff colSpan=2 height=32>
<P align=center>修改商品信息</P></TD>
</TR>
<TD align=right>大图片:</TD>
<TD align=left> <% if (ps.getMaxPicture() != null) { %>
<img src="<%="../../../"+"productpic" + "\\" +ps.getMaxPicture()%>" height="25"
width="50"><% } else { %>
--<% } %> <INPUT type="file" size=45 name=maxpicture value="" onpropertychange="f(this)">
</TD>
</TR>
<TR height=32>
<TD align=right>小图片:</TD>
<TD align=left> <% if (ps.getMinPicture() != null) { %>
<img src="<%="../../../"+"productpic" + "\\" +ps.getMinPicture()%>" height="25"
width="50"><% } else { %>
--<% } %> <INPUT type="file" size=45 name=minpicture value="" onpropertychange="f(this)"></TD>
</TR>
<TR height=32>
<TD align=right>特效图:</TD>
<TD align=left> <% if (ps.getSpecificPicture() != null) { %>
<img src="<%="../../../"+"productpic" + "\\" +ps.getSpecificPicture()%>" height="25"
width="50"><% } else { %>
--<% } %> <INPUT type="file" size=45 name=specificpicture value="" onpropertychange="f(this)">
</TD>
</TR>
<TR height=32>
<TD align=right>原图:</TD>
<TD align=left> <% if (ps.getPicture() != null) { %>
<img src="<%="../../../"+"productpic" + "\\" +ps.getPicture()%>" height="25"
width="50"><% } else { %>
--<% } %> <INPUT type="file" size=45 name=picture value="" onpropertychange="f(this)"></TD>
</TR>
<TR height=32>
<TD align=right>标题图:</TD>
<TD align=left> <% if (ps.getTitlePicture() != null) { %>
<img src="<%="../../../"+"productpic" + "\\" +ps.getTitlePicture()%>" height="25"
width="50"><% } else { %>
--<% } %> <INPUT type="file" size=45 name=titlepicture value="" onpropertychange="f(this)">
</TD>
</TR>
<TR height=32>
<TD align=right>原标题图:</TD>
<TD align=left> <% if (ps.getBornTitlePicture() != null) { %>
<img src="<%="../../../"+"productpic" + "\\" +ps.getBornTitlePicture()%>" height="25"
width="50"><% } else { %>
--<% } %> <INPUT type="file" size=45 name=borntitelpicture value="" onpropertychange="f(this)">
</TD>
</TR>
<TR height=32>
<TD colSpan=2><FONT
color=red> 注:带有*的项为必填项</FONT></TD>
</TR>
</TBODY>
</TABLE>
<P align=center><INPUT onclick="javascript:return check();" type=submit value=" 确 认 " name=Ok>
<INPUT onclick=javascript:goto(); type=button value=返回列表 name=golist>
</P>
</CENTER>
</FORM>
</BODY>
</HTML>
解决方案 »
- 请大家解答某公司笔试题
- AXIS2的Web Service服务端,用xfire客户端调用报“Could not find a service to invoke.”
- SOA中也存在抄袭??
- J2EE最基础的问题
- 请大家帮忙推荐以下 学习 spring / Hibernate / Structs 的入门的书,谢谢
- 请不要吝啬口水?!!~~~
- 那有象CSDN一样的技术论坛
- 感觉ant真的不过如此,真纳闷为什么那么多人要花时间学这个
- Apusic??
- 哪里能找到《J2EE core design pattern》英文版电子书,300分送上
- 求助 关于el表达式问题。
- struts2获取表单中的<select>值的问题
com.bizwink.cms.kings.jspsmart.upload.File tmpFile = null;
这个 你看看