apache好像提供了一个包commons-fileupload-1.0.jar
有用过的大虾,帮忙指导一下。

解决方案 »

  1.   

    我用的是myfaces,它是jsf的扩展,和jsf是完全支持的,组件用法也是一样的,这是服务器端获取你上传文件的类 ,你应该把它定义成一个managed-bean,在我的项目里面,
    我把它定义为fileupload,我想managed bean的定义你应该清楚吧,后面的是文件上传组件的的应用,那个代码是页面中的应用,
    import java.io.IOException;import org.apache.myfaces.custom.fileupload.UploadedFile;import javax.faces.context.FacesContext;
    public class FileUploadForm
    {
        private UploadedFile _upFile;
        private String _name = "";    public UploadedFile getUpFile()
        {
            return _upFile;
        }    public void setUpFile(UploadedFile upFile)
        {
            _upFile = upFile;
        }    public String getName()
        {
            return _name;
        }    public void setName(String name)
        {
            _name = name;
        }    public String upload() throws IOException
        {
            FacesContext facesContext = FacesContext.getCurrentInstance();
            facesContext.getExternalContext().getApplicationMap().put("fileupload_bytes", _upFile.getBytes());
            facesContext.getExternalContext().getApplicationMap().put("fileupload_type", _upFile.getContentType());
            facesContext.getExternalContext().getApplicationMap().put("fileupload_name", _upFile.getName());
            return "ok";
        }       public boolean isUploaded()
        {
            FacesContext facesContext = FacesContext.getCurrentInstance();
            return facesContext.getExternalContext().getApplicationMap().get("fileupload_bytes")!=null;
        }}
    //放在form里面                <h:form id="form1" name="form1" enctype="multipart/form-data" >
    <x:inputFileUpload id="fileupload" accept="application/vnd.ms-excel"
    value="#{fileupload.upFile}" storage="file"
    styleClass="fileUploadInput" required="true" />
                       此处是按钮,点击执行managed bean:fileupload的文件上传方法:upload
    <h:commandButton type="submit" action="#{fileupload.upload}" value="上传文件" styleClass="button-main-4"/>
                    </h:form>
      

  2.   

    楼上的真强
    用smartupload.jar也可以啊。
    smartupload的使用方法就简单的很啊。网上搜一下吧
      

  3.   

    to:wudouguerwxx(家有小熊)
    这个包你在哪里找的,我从apache网站当的包里没有
    org.apache.myfaces.custom
    我当的包是apache的myfaces-1.1.1
      

  4.   

    to:wudouguerwxx(家有小熊)找到了,多谢了