• day3——关于<s:if/>和文件上传


    一个小的注意点

    <s:if test='#backyear==#yearatd'>selected="selected"</s:if> 

    <s:if test='%{#backmonth==-1}'>selected="selected"</s:if>

    文件上传(struts2)

    jsp:

      <form name="myform" method="post" action="employeesAdd" enctype="multipart/form-data">

      <p><span>上传头像:</span><input type="file" class="txtinput" name="upload" /></p>

    Action:

      //上传文件 
      private File upload;

      //上传文件名
      private String uploadFileName;
      //上传文件类型
      private String uploadContentType;

     

      //....getter、setter

      

      public String AddEmployee(){

        //项目路径
        String root = ServletActionContext.getServletContext().getRealPath("/");

        //文件存放目录
        String filepath = root+File.separatorChar+"upload";
      try {

        //复制文件到服务器中
        FileUtils.copyFile(upload, new File(filepath,uploadFileName));

        //访问文件的路径(File.separatorChar相当于"/")
        String imgurl = "upload"+File.separatorChar+uploadFileName;


        employee.setEpicture(imgurl);
        
      } catch (IOException e) {
        // TODO Auto-generated catch block
      e.printStackTrace();
      }
      employeesService.addEmployee(employee);
      return SUCCESS;
      }

  • 相关阅读:
    [loj3031]聚会
    [loj3146]路灯
    [loj2049]网络
    [luogu7599]雨林跳跃
    [loj3069]整点计数
    [loj3301]魔法商店
    [loj3333]混合物
    [cf1515I]Phoenix and Diamonds
    [cf1515H]Phoenix and Bits
    [atARC116F]Deque Game
  • 原文地址:https://www.cnblogs.com/whisper527/p/6498863.html
Copyright © 2020-2023  润新知