在action中使用request.getAttribute("..")得不到你要的简单参数对象?
因为你的form提交类型成为了:multipart/data
所以struts在处理请求的时候只是将file放到了formbean中
其它的简单参数你需要自己取
对了,还有,你用struts无法实现多文件上传(一个表单提交多个文件)

解决方案 »

  1.   

    你去看看Struts自带的例子,有上传文件的!且很简单的。
      

  2.   

    请使用:common-upload,三句代码事线你的功能,将代码放在ActionForm里面就可以了。
      

  3.   

    struts自带上传文件,用FormFile对象
    至于楼上说的无法实现多文件上传应该也不成问题,我试过同时上传2个文件。
      

  4.   

    回复人: szabo(阿波哥)    这个我知道,分开来做这是可以的,比较简单。但是要一起提交,似乎办不到。   你知道无论是yahoo,还是sina等那些基于B/S交互的邮箱上传附件的时候都是先把附件
       
       upload到server短,然后再把邮件发出去的。   我想实现的是一起发出去,把无论是下拉框还是文本框数据。(没有办法,客户需要这样,晕!)to: vgvg(成功靠自己) ( 
    一步不行,就分两步,先提交文件
    然后提交普通参数数据.期待高人.
    =================================
    这个听起来不错,劳驾您说详细些,谢谢!
      

  5.   

    =====  大家看看这段代码(转)是不是很有价值,我正在实现中,估计应该不会有问题。有高见请评论===public class FileAction extends Action {
      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;
      }
    }
      

  6.   

    少量数据放到URL里是可以取到的不是getParameter()罢了
      

  7.   

    可以实现一起上传跟提交数据的,在form bean 中
    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()); 打印出的结果就知道了,昨天刚研究过的。