在action中使用request.getAttribute("..")得不到你要的简单参数对象?
因为你的form提交类型成为了:multipart/data
所以struts在处理请求的时候只是将file放到了formbean中
其它的简单参数你需要自己取
对了,还有,你用struts无法实现多文件上传(一个表单提交多个文件)
因为你的form提交类型成为了:multipart/data
所以struts在处理请求的时候只是将file放到了formbean中
其它的简单参数你需要自己取
对了,还有,你用struts无法实现多文件上传(一个表单提交多个文件)
解决方案 »
- html使用ajax+cookie session会丢失??改为jsp就可以了-诡异!!!
- 在拷贝文件的时候报系统找不到路径???
- javax.servlet.ServletException: java.lang.OutOfMemoryError: PermGen space
- Spring3.0.3+Hibernate3.6 整合sessionFactory 出错,一直调不好?
- resin 急,在线等
- 请教:实用的java 反编译软件
- hibernate概念问题,50分!
- Struts validate的问题!
- JB7生成EXE,运行结果和在JB中运行不一样
- 求大神解决Hibernate问题
- JTable中单元格组件的显示问题(顶者有分 )
- jndi问题?高手指点
至于楼上说的无法实现多文件上传应该也不成问题,我试过同时上传2个文件。
upload到server短,然后再把邮件发出去的。 我想实现的是一起发出去,把无论是下拉框还是文本框数据。(没有办法,客户需要这样,晕!)to: vgvg(成功靠自己) (
一步不行,就分两步,先提交文件
然后提交普通参数数据.期待高人.
=================================
这个听起来不错,劳驾您说详细些,谢谢!
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
// if (form instanceof uploadsForm) {//如果form是uploadsForm
String encoding = request.getCharacterEncoding();
if ((encoding != null) && (encoding.equalsIgnoreCase("utf-8")))
{
response.setContentType("text/html; charset=gb2312");//如果没有指定??,??格式?gb2312
}
FileBean theForm = ( FileBean ) form;
FormFile file = theForm.getFile();//取得上?的文件
try {
InputStream stream = file.getInputStream();//把文件?入
String filePath = request.getRealPath("/");//取当前系?路径
ByteArrayOutputStream baos = new ByteArrayOutputStream();
OutputStream bos = new FileOutputStream(filePath + "/" +
file.getFileName());//建立一个上?文件的?出流
//System.out.println(filePath+"/"+file.getFileName());
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();
}catch(Exception e){
System.err.print(e);
}
//request.setAttribute("dat",file.getFileName());
return mapping.findForward("display");
// }
// return null;
}
}
ServletInputStream in = req.getInputStream();
StringBuffer result = new StringBuffer();
byte[] line = new byte[128];
int i = in.readLine(line, 0, 128);
while(i!=-1){
result.append(new String(line,0,i));
i = in.readLine(line, 0, 128);
}
再把得到的line 进行拆分。看看System.out.println(result.toString()); 打印出的结果就知道了,昨天刚研究过的。