zoukankan      html  css  js  c++  java
  • 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;
      }

  • 相关阅读:
    Linux安全加固
    mosquitto
    Docker设置2375端口
    linux shell 常见的时间戳操作
    tar打包并且排除log目录
    spring boot2整合shiro安全框架实现前后端分离的JWT token登录验证
    http post
    scp命令 Linux和Windows文件互传
    git did not exit cleanly (exit code 1) 的解决办法
    windows安装TortoiseGit详细使用教程【基础篇】
  • 原文地址:https://www.cnblogs.com/whisper527/p/6498863.html
Copyright © 2011-2022 走看看