jsf和myface上传文件

news/2024/7/2 21:30:56 标签: jsf, string, file, upload, null, class
class="baidu_pl">
class="article_content clearfix">
class="htmledit_views">

 class="tags" href="/tags/JSF.html" title=jsf>jsf和myface上传文件
气死我了


<%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="x"%>
 <h:form id="createForm" enctype="multipart/form-data">
<td class="tdbg4" width="100">
       上传附件:
      </td>
      <td class="tdbg5" width="400" colspan="3">

       <a4j:region>
        <input type=hidden" value="0" name="class="tags" href="/tags/UPLOAD.html" title=upload>uploadedFileNum"
         id="class="tags" href="/tags/UPLOAD.html" title=upload>uploadedFileNum" />
        <h:panelGroup id="class="tags" href="/tags/UPLOAD.html" title=upload>uploadedFilePanel">
         <x:inputFileUpload value="#{projectBean.class="tags" href="/tags/UPLOAD.html" title=upload>uploadedFile[0]}"
          id="class="tags" href="/tags/UPLOAD.html" title=upload>uploadedFile0" storage="class="tags" href="/tags/FILE.html" title=file>file" />
         <x:inputFileUpload value="#{projectBean.class="tags" href="/tags/UPLOAD.html" title=upload>uploadedFile[1]}"
          id="class="tags" href="/tags/UPLOAD.html" title=upload>uploadedFile1" storage="class="tags" href="/tags/FILE.html" title=file>file" rendered="false" />
         <x:inputFileUpload value="#{projectBean.class="tags" href="/tags/UPLOAD.html" title=upload>uploadedFile[2]}"
          id="class="tags" href="/tags/UPLOAD.html" title=upload>uploadedFile2" storage="class="tags" href="/tags/FILE.html" title=file>file" rendered="false" />
         <x:inputFileUpload value="#{projectBean.class="tags" href="/tags/UPLOAD.html" title=upload>uploadedFile[3]}"
          id="class="tags" href="/tags/UPLOAD.html" title=upload>uploadedFile3" storage="class="tags" href="/tags/FILE.html" title=file>file" rendered="false" />
         <x:inputFileUpload value="#{projectBean.class="tags" href="/tags/UPLOAD.html" title=upload>uploadedFile[4]}"
          id="class="tags" href="/tags/UPLOAD.html" title=upload>uploadedFile4" storage="class="tags" href="/tags/FILE.html" title=file>file" rendered="false" />
         <x:inputFileUpload value="#{projectBean.class="tags" href="/tags/UPLOAD.html" title=upload>uploadedFile[5]}"
          id="class="tags" href="/tags/UPLOAD.html" title=upload>uploadedFile5" storage="class="tags" href="/tags/FILE.html" title=file>file" rendered="false" />
         <x:inputFileUpload value="#{projectBean.class="tags" href="/tags/UPLOAD.html" title=upload>uploadedFile[6]}"
          id="class="tags" href="/tags/UPLOAD.html" title=upload>uploadedFile6" storage="class="tags" href="/tags/FILE.html" title=file>file" rendered="false" />
         <x:inputFileUpload value="#{projectBean.class="tags" href="/tags/UPLOAD.html" title=upload>uploadedFile[7]}"
          id="class="tags" href="/tags/UPLOAD.html" title=upload>uploadedFile7" storage="class="tags" href="/tags/FILE.html" title=file>file" rendered="false" />
         <x:inputFileUpload value="#{projectBean.class="tags" href="/tags/UPLOAD.html" title=upload>uploadedFile[8]}"
          id="class="tags" href="/tags/UPLOAD.html" title=upload>uploadedFile8" storage="class="tags" href="/tags/FILE.html" title=file>file" rendered="false" />
         <x:inputFileUpload value="#{projectBean.class="tags" href="/tags/UPLOAD.html" title=upload>uploadedFile[9]}"
          id="class="tags" href="/tags/UPLOAD.html" title=upload>uploadedFile9" storage="class="tags" href="/tags/FILE.html" title=file>file" rendered="false" />
        </h:panelGroup>
        <a4j:commandLink value="添加上传文件"
         action="#{projectBean.addUploadedFilePanel}"
         οnclick="document.getElementById('class="tags" href="/tags/UPLOAD.html" title=upload>uploadedFileNum').value=parseInt(document.getElementById('class="tags" href="/tags/UPLOAD.html" title=upload>uploadedFileNum').value)+1;"
         reRender="class="tags" href="/tags/UPLOAD.html" title=upload>uploadedFilePanel">
        </a4j:commandLink>
       </a4j:region>

 

ProjectBean中
 /**
  * AjAX处理
  */
 public void addUploadedFilePanel() {
  UIComponent panel = FacesContext.getCurrentInstance().getViewRoot()
    .findComponent("createForm:class="tags" href="/tags/UPLOAD.html" title=upload>uploadedFilePanel");
  String class="tags" href="/tags/UPLOAD.html" title=upload>uploadedFileNum = (String) FacesUtils
    .getRequestParameter("class="tags" href="/tags/UPLOAD.html" title=upload>uploadedFileNum");
  panel.findComponent("class="tags" href="/tags/UPLOAD.html" title=upload>uploadedFile" + class="tags" href="/tags/UPLOAD.html" title=upload>uploadedFileNum).setRendered(true);
 }

 private UploadedFile[] class="tags" href="/tags/UPLOAD.html" title=upload>uploadedFile;

 /**
  * 上传的文件
  */
 public UploadedFile[] getUploadedFile() {
  String class="tags" href="/tags/UPLOAD.html" title=upload>uploadedFileNum = (String) FacesUtils
    .getRequestParameter("class="tags" href="/tags/UPLOAD.html" title=upload>uploadedFileNum");
  if (class="tags" href="/tags/UPLOAD.html" title=upload>uploadedFile == class="tags" href="/tags/NULL.html" title=null>null) {
   if (class="tags" href="/tags/UPLOAD.html" title=upload>uploadedFileNum != class="tags" href="/tags/NULL.html" title=null>null && !class="tags" href="/tags/UPLOAD.html" title=upload>uploadedFileNum.equals("")) {
    class="tags" href="/tags/UPLOAD.html" title=upload>uploadedFile = new UploadedFile[Integer.parseInt(class="tags" href="/tags/UPLOAD.html" title=upload>uploadedFileNum) + 1];
   } else {
    class="tags" href="/tags/UPLOAD.html" title=upload>uploadedFile = new UploadedFile[1];
   }
  }
  return class="tags" href="/tags/UPLOAD.html" title=upload>uploadedFile;
 }
//上传文件
 public void upLoad() throws IOException {
  if (class="tags" href="/tags/UPLOAD.html" title=upload>uploadedFile.length != 0) {
   String class="tags" href="/tags/UPLOAD.html" title=upload>uploadDir = FacesUtils.getServletContext().getRealPath(
     "//class="tags" href="/tags/UPLOAD.html" title=upload>upload//applyProject//");
   class="tags" href="/tags/UPLOAD.html" title=upload>uploadDir += "//" + FacesUtils.getCurrentUserName() + "//";
   FileUntils class="tags" href="/tags/FILE.html" title=file>fileUntils = new FileUntils();
   class="tags" href="/tags/FILE.html" title=file>fileUntils.createFolder(class="tags" href="/tags/UPLOAD.html" title=upload>uploadDir);
   Attachment[] attachment = new Attachment[class="tags" href="/tags/UPLOAD.html" title=upload>uploadedFile.length];
   for (int i = 0; i < class="tags" href="/tags/UPLOAD.html" title=upload>uploadedFile.length; i++) {
    if (class="tags" href="/tags/UPLOAD.html" title=upload>uploadedFile[i]!= class="tags" href="/tags/NULL.html" title=null>null) {
     File tempUploadFile = new File(class="tags" href="/tags/UPLOAD.html" title=upload>uploadedFile[i].getName());

     String class="tags" href="/tags/FILE.html" title=file>fileName = tempUploadFile.getName();
     int length = (int) tempUploadFile.length();

     String completePath = class="tags" href="/tags/UPLOAD.html" title=upload>uploadDir + "//"
       + UniqueStringGenerator.getUniqueString();
     class="tags" href="/tags/FILE.html" title=file>fileUntils.createFolder(completePath);
     String floder = completePath;
     completePath = completePath + "//" + class="tags" href="/tags/FILE.html" title=file>fileName;
     class="tags" href="/tags/FILE.html" title=file>fileUntils.createFile(class="tags" href="/tags/UPLOAD.html" title=upload>uploadedFile[i].getInputStream(),
       completePath);
     attachment[i] = new Attachment();
     attachment[i].setFileName(class="tags" href="/tags/FILE.html" title=file>fileName);
     attachment[i].setFileSize(length);
     attachment[i].setPath(completePath);
     attachment[i].setFloder(floder);
     attachment[i].setProject(project);
     project.getAttachments().add(attachment[i]);
    }
   }
  }

 }

 public void setUploadedFile(UploadedFile[] class="tags" href="/tags/UPLOAD.html" title=upload>uploadedFile) {
  this.class="tags" href="/tags/UPLOAD.html" title=upload>uploadedFile = class="tags" href="/tags/UPLOAD.html" title=upload>uploadedFile;
 }

 

 

不有确定按钮的add {class="tags" href="/tags/UPLOAD.html" title=upload>upload()...}

Project与attach一对多的关系。

 


http://www.niftyadmin.cn/n/1425406.html

相关文章

python用字典编写购物程序_day 5 - 2 字典(dict)练习

1. 有如下变量&#xff08;tu 是个元祖&#xff09;&#xff0c;请实现要求的功能 tu {"alex",[11,22,{"k1":v1,"k2":["age","name"],"k3":(11,22,33)},44]} #1&#xff09;讲述元祖的特性 子元素不可以被修改&a…

jsf的安全问题

如果破解一个系统的代价比系统本来内容的价值还要高&#xff0c;则系统就是安全的。1口令加密存储 相同的密码在数据库中显示的值不一定相同,这就是加盐的效果。知识补充&#xff1a;1&#xff09;JAVA密码架构&#xff08;JCA&#xff09;是由java.security包和子包中的一系…

并联系统的失效率公式推导步骤_小学数学一类求阴影部分周长和面积,记住两个公式就够了...

同学们好&#xff0c;我是小升初数学课堂。在小学数学学习的过程当中&#xff0c;我们要学会不断的总结。如果把一类题目&#xff0c;总结到位&#xff0c;下次再碰到这类题目就很轻松的解决了&#xff0c;比如说在学习六年级圆的当中&#xff0c;有一类求阴影部分周长和面积的…

selenium设置元素等待(python)

WebDriver提供了两种类型的元素等待&#xff1a;显式等待和隐式等待。 显式等待&#xff1a;WebDriver等待某个条件成立则继续执行&#xff0c;否则在达到最大时长时抛出超时异常(TimeoutException) WebDriverWait类是WebDriver提供的等待方法。在设置的时间内&#xff0c;默认…

MyEclipse 快捷键大全

CtrlQ跳到最后一次的编辑处F7由函数内部返回到调用处。F8一直执行到下一个断点。CtrlShiftS保存所有未保存的文件。Ctrl1 快速修复AltEnter 显示当前选择资源(工程,or 文件 or文件)的属性 ShiftEnter 在当前行的下一行插入空行(这时鼠标可以在当前行的任一位置,不一定是最后)S…

docker 覆盖 entrypoint_Docker基础教程(2)-如何创建一个定制镜像并上传到DockerHub

如果对Docker还不是很了解的同学可以先看一下我之前的文章Docker基础教程(1)定制镜像的两种方式将容器打包成镜像容器和镜像之间是可以互相转变的,镜像可以运行成容器,容器也可以打包成镜像,可以将所有数据打包起来,原封不动的变成一个镜像 首先了解一下打包的命令docker commi…

结构体中函数应该怎样定义才能返回值_单片机编程时可变参函数的实现

新的多功能使用主控模块块的设计&#xff0c;板与板之间使用自定的协议来传递数据&#xff0c;在程序书写上&#xff0c; 我希望写成一个通用的数据协议&#xff0c;这样这个协议可以在后续直接移植我以后相当长一个时间内的其它产品上&#xff0c;这其中就需要用到可变参函数。…

jsf上下文取request

通过faces上下文和外部上下文获得request对象FacesContext facesContextFacesContext.getCurrentInstance();HttpServletRequest request (HttpServletRequest)facesContext.getExternalContext().getRequest(); 获得session对象HttpSession sessionrequest.getSession(); St…