Ejemplo n.º 1
0
  @Override
  public String execute() throws Exception {
    // TODO Auto-generated method stub
    messageModel = new MessageModel();
    SecurityAction securityAction = new SecurityAction();
    if (!securityAction.checkTeacher()) {
      return "login";
    }
    // 验证用户是否有下载文件的权限

    try {
      homeworkIdInteger = Integer.parseInt(homeworkId);
    } catch (Exception e) {
      // TODO: handle exception
      messageModel.setData(
          "系统提示",
          "操作非法,你的ip:" + ServletActionContext.getRequest().getRemoteAddr() + "已被系统记录。",
          "classInfo.action");
      return "message";
    }
    Task task = null;
    try {
      task =
          taskService.getTaskById(homeworkService.getHomeworkById(homeworkIdInteger).getTaskId());
    } catch (Exception e) {
      // TODO: handle exception
      messageModel.setData(
          "系统提示",
          "您无权下载此文件,你的ip:" + ServletActionContext.getRequest().getRemoteAddr() + "已被系统记录。",
          "classInfo.action");
      return "message";
    }

    if (securityAction.getType() == 0) {
      return SUCCESS;
    }
    if (task == null || !task.getUserId().equals(securityAction.getUserId())) {
      messageModel.setData(
          "系统提示",
          "您无权下载此文件,你的ip:" + ServletActionContext.getRequest().getRemoteAddr() + "已被系统记录。",
          "classInfo.action");
      return "message";
    }
    return SUCCESS;
  }
Ejemplo n.º 2
0
 public InputStream getTargetFile() throws Exception {
   String string = homeworkService.getHomeworkById(homeworkIdInteger).getPath();
   filename = string.split("/")[string.split("/").length - 1];
   return new FileInputStream(string);
 }