67,537
社区成员
发帖
与我相关
我的任务
分享
<form action="ware.do" method="get" enctype="multipart/form-data">
<input type="hidden" name="method" value="modify">
<!-- 这里真的是比较难啊,搞了半天 -->
<input type="hidden" name="id" value="${ware.id}">
<TABLE class="tableEdit" border="0" cellspacing="1" cellpadding="0" style="width:580px;">
<TBODY>
<TR>
<!-- 这里是添加、编辑界面的标题 -->
<td align="center" class="tdEditTitle">修改宠物员信息</TD>
</TR>
<TR>
<td>
<!-- 主输入域开始 -->
<table class="tableEdit" style="width:580px;" cellspacing="0" border="0" cellpadding="0">
<tr>
<td class="tdEditLabel" >宠物名</td>
<td class="tdEditContent"><input type="text" name="name" value="${ware.name }">
</td>
</tr>
<tr>
<td class="tdEditLabel" >价格</td>
<td class="tdEditContent"><input type="text" name="price" value="${ware.price }"></td>
</tr>
<tr>
<td class="tdEditLabel" >照片上传</td>
<td class="tdEditContent">
<input type="file" name="photo">
</td>
</tr>
<tr>
<td class="tdEditLabel" >描述</td>
<td class="tdEditContent"><textarea STYLE="font-size:10pt;font-family:verdana;color:#333333" name="description">${ware.description }</textarea></td>
</tr>
</table>
<!-- 主输入域结束 -->
</td>
</TR>
</TBODY>
</TABLE>
<TABLE>
<TR align="center">
<TD colspan="3" bgcolor="#EFF3F7">
<input type="submit" name="saveButton"
class="MyButton" value="保存宠物信息">
<input type="button" class="MyButton"
value="关闭窗口" onclick="window.close()">
</TD>
</TR>
</TABLE>
</form>
public class WareActionForm extends ActionForm {
private int id;
private String name;
private BigDecimal price;
private String photourl;
private FormFile photo;
private String description;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public BigDecimal getPrice() {
return price;
}
public void setPrice(BigDecimal price) {
this.price = price;
}
public String getPhotourl() {
return photourl;
}
public void setPhotourl(String photourl) {
this.photourl = photourl;
}
public FormFile getPhoto() {
return photo;
}
public void setPhoto(FormFile photo) {
this.photo = photo;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
public ActionForward modify(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
WareActionForm waf = (WareActionForm) form;
int id = waf.getId();
Ware ware = wareManager.findWare(id);
FormFile photo = waf.getPhoto();
if(photo != null) {
System.out.println(photo.getFileSize());
FileOutputStream fos = new FileOutputStream("D:\\workstation\\spring\\petstore\\WebRoot\\images\\" + photo.getFileName());
fos.write(photo.getFileData());
fos.flush();
fos.close();
}
ware.setName(waf.getName());
//ware.setPhotourl(photo.getFileName());
ware.setPrice(waf.getPrice());
wareManager.modifyWare(ware);
return mapping.findForward("public_modify_success");
}tr>
<td class="tdEditLabel" >照片上传</td>
<td class="tdEditContent">
<input type="file" name="photo">
</td>
</tr>