有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java xlsx文件在http请求中发送时已损坏/为空(0字节)

我正在通过http请求发送xlsx文件,但该文件已损坏。 我只是不明白为什么文件在发送时会损坏。 请帮忙,我是新手

以下是jsp文件:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html ng-app="myApplication">

<head>
<!-- <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> -->

<title>Preptune</title>

 <meta name="viewport" content="width=device-width, initial-scale=1">
 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-route.js"></script>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  <script>

   angular.module('myApplication',["ngRoute"]).
   directive('fileInput',['$parse',function($parse){
    return {
        restrict:'A',
        link: function(scope,elm,attrs) {
            elm.bind('change',function() {
                $parse(attrs.fileInput)
                .assign(scope,elm[0].files)
                scope.$apply()
            })
        }
    }
   }])
   .controller('myController',['$scope','$http',
                function($scope,$http) {
    $scope.message = "Test message";
    $scope.filesChanged = function(elm) {
        $scope.files=elm.files;
        $scope.$apply();
    };
    $scope.upload = function() {
        var fd = new FormData();
        angular.forEach($scope.files,function(file){
            fd.append('file',file);
        })
        $http.post('http://localhost:80/simple-web-services/uploadQuestions', fd,{
            transformRequest : angular.identity,
            headers:{'Content-Type':undefined}
        })
        .success(function(d){
            console.log(d);
        })
    };
     }
   ])
   .config(function($routeProvider) {
        $routeProvider
        .when("/preptune", {
            templateUrl : "/webPortal/homePage/welcome"
        })
        .when("/upload", {
            templateUrl : "/webPortal/resources/html/uploadQuestion.html"
        })
        .when("/download", {
            templateUrl : "/webPortal/resources/html/downloadTemplate.html"
        })
        .otherwise({redirectTo:'/'});
    });

  </script>
</head>
<body ng-controller="myController">

<nav class="navbar navbar-default">
  <div class="container-fluid bg-info">
    <div class="navbar-header">
      <a class="navbar-brand" href="#prep">Prep</a>
    </div>
    <ul class="nav navbar-nav">
      <li><a href="#upload">Upload Question Paper</a></li>
      <li><a href="#download">Download Question Template</a></li>
    </ul>
  </div>
</nav>

<div ng-view></div>

</body>
</html>

这是表格:(uploadQuestion.html)

<form method="post">
<input type="file" 
file-input="files"
 multiple></input>
<button ng-click="upload()"> Upload </button>
 <li ng-repeat="file in files" >{{file.name}} </li>
</form>

例外情况是 JAVAlang.RuntimeException:org。阿帕奇。cxf。拦截器。错误:您的InputStream既不是OLE2流,也不是OOXML流


共 (0) 个答案