上传页面:
<form action="upload.do?method=testUpload" enctype="multipart/form-data" method="post" >
<p>用户名:
<input name="user.userName" type="text" id="userName" />
</p>
<p>密码:
<input name="user.pwd" type="password" id="userPwd" />
</p>
<p>头像:
<input type="file" name="file" id="filepic" onchange="viewPic();" />
</p>
<p>
<input type="submit" name="send" value="提交" />
</p>
<p>
</p>
</form>但是:在struts配置文件中<action
attribute="fileForm"
name="fileForm"
parameter="method"
path="/upload"
type="com.upload.action.UploadAction" >
<forward name="file" path="/upload.jsp"></forward>
</action>
当加上红色部分代码无法上传, 如果去掉可以上传图片,但是不能获取form 中的userName, pwd 的值————————求助,
<form action="upload.do?method=testUpload" enctype="multipart/form-data" method="post" >
<p>用户名:
<input name="user.userName" type="text" id="userName" />
</p>
<p>密码:
<input name="user.pwd" type="password" id="userPwd" />
</p>
<p>头像:
<input type="file" name="file" id="filepic" onchange="viewPic();" />
</p>
<p>
<input type="submit" name="send" value="提交" />
</p>
<p>
</p>
</form>但是:在struts配置文件中<action
attribute="fileForm"
name="fileForm"
parameter="method"
path="/upload"
type="com.upload.action.UploadAction" >
<forward name="file" path="/upload.jsp"></forward>
</action>
当加上红色部分代码无法上传, 如果去掉可以上传图片,但是不能获取form 中的userName, pwd 的值————————求助,
<action path="/upload" name="uploadForm" type="web.UploadAction" parameter="o">
</action>表单
<html:form action="upload.do?o=upload" method="post" enctype="multipart/form-data">
<html:file property="uploadFile"></html:file>
<html:submit value="上传"/>
</html:form>
action类
public ActionForward upload(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws FileNotFoundException, IOException {
DynaActionForm uploadForm = (DynaActionForm) form;// TODO Auto-generated method stub
FormFile file=(FormFile)uploadForm.get("uploadFile");
String fileName=file.getFileName();
fileName=request.getRealPath("/upload")+"/"+fileName;
byte[] buffer=new byte[100*1024];
int length=-1;
InputStream in=file.getInputStream();
FileOutputStream out=new FileOutputStream(fileName);
while((length=in.read(buffer))!=-1){
out.write(buffer, 0, length);
}
in.close();
out.close();
return null;
}