删除服务器上的图片
我是用ss2h做的我上传图片到服务器上,地址上传到数据库中,这是成功的,可是我删除就不行了,服务器上的图片删不了,获取不到img的值,我都找了好久了,实在没办法,还得请大神们看看
public String deleteTest(){
testBiz.delTest(shopPoster.getId());
String savePath = ServletActionContext.getServletContext().getRealPath(
""); // 获取项目根路径
savePath = savePath + "/upload/";
File file=new File(savePath+shopPoster.getContext());
file.delete();
resultMap="testActionshow.action";
return SUCCESS;
}
jsp上的 <script type="text/javascript">
function del(id){
location.href="shopEcsVoteOptiondeletePoster.action?shopPoster.id="+id
}
function ret(){
location.href="addPoster.jsp";
}
</script>
<body ><!--
<form action="shopEcsVoteOptiondeletePosters.action" method="post" name="myForm">
--><table align="center" border="1">
<s:iterator value="#request['listShopPoster']" var="listShopPoster">
<tr>
<td>
<img src="Poster/<s:property value="#listShopPoster.context"/>" height="50" width="50" />
</td>
<td>
<input type="button" value="删除" onclick="del(<s:property value="#listShopPoster.id"/>)">
</td>
</tr>
</s:iterator>
<tr>
<td>
<input type="button" value="继续添加" onclick="ret()">
</td>
</tr>
</table><!--
</form>
--></body>
public String deleteTest(){
testBiz.delTest(shopPoster.getId());
String savePath = ServletActionContext.getServletContext().getRealPath(
""); // 获取项目根路径
savePath = savePath + "/upload/";
File file=new File(savePath+shopPoster.getContext());
file.delete();
resultMap="testActionshow.action";
return SUCCESS;
}
jsp上的 <script type="text/javascript">
function del(id){
location.href="shopEcsVoteOptiondeletePoster.action?shopPoster.id="+id
}
function ret(){
location.href="addPoster.jsp";
}
</script>
<body ><!--
<form action="shopEcsVoteOptiondeletePosters.action" method="post" name="myForm">
--><table align="center" border="1">
<s:iterator value="#request['listShopPoster']" var="listShopPoster">
<tr>
<td>
<img src="Poster/<s:property value="#listShopPoster.context"/>" height="50" width="50" />
</td>
<td>
<input type="button" value="删除" onclick="del(<s:property value="#listShopPoster.id"/>)">
</td>
</tr>
</s:iterator>
<tr>
<td>
<input type="button" value="继续添加" onclick="ret()">
</td>
</tr>
</table><!--
</form>
--></body>
...全文
相关推荐
java图片上传到服务器以及在服务器上图片修改删除
java图片上传到服务器以及在服务器上图片修改删除,可以从前端获取图片后端接收然后保存,还可以修改图片修改之前会删除原来的图片。
fckeditor删除服务器图片
fckeditor删除服务器图片很灵的!!!
Javascript和asp.net实现多个图片文件一起上传到服务,同时实现删除服务器上上传的图片功能
JavaScript和asp.net实现多张图片上传功能。原生js实现图片单张上传及批量上传,为初学者提供一个思路,一种参考。
C#項目中實現圖片的上傳(上傳至服務器項目指定文件夾內)和顯示,并定期刪除文件(30天之前)
博客文章:“C#項目中實現圖片的上傳(上傳至服務器項目指定文件夾內)和顯示,并定期刪除文件(30天之前)”中的源碼。 工具:vs2013/2017
通过网页上传图片到服务器删的源代码
通过网页上传图片到服务器删的源代码,可以使用网页浏览到



