在html页面上打印html响应

时间:2017-06-19 02:28:02

标签: javascript java html angularjs

我在应用程序中使用angularjs和springmvc。我的要求是点击网页(URL)和它返回的任何响应(基本上它返回通过URL访问的网页的html内容)我需要在html页面上显示。 以下是我的代码:

one.html

myApp
    .controller("getHtmlDataController", [
        "$scope", 'MyService',
        function ($scope, MyService) {

            MyService.fetch().then(function (response) {
                $scope.htmlResponsedata = response;
            }, function (errResponse) {
                $scope.cancelModal();
                $rootScope.showError(500, "Internal error");
            });

            _myServiceFactory.fetch = function () {
                var deferred = $q.defer();
                var repUrl = myAppURL + '/percentValues/' + '/getHtmlData.form';
                $http.get(repUrl).then(function (response) {
                        console.log("response");
                        derred.resolve(response.data);
                    },
                    function (errResponse) {
                        console.error('Error while fetching data');
                        deferred.reject(errResponse);
                    }
                );
                return deferred.promise;
            }

        }

    ]);

的JavaScript

@RequestMapping(value = "/getHtmlData", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    public  @ResponseBody String getHtmlData() throws Exception {

      URL url = new URL("https://xyz/abc.com/values/reports");
        HttpsURLConnection connection = ((HttpsURLConnection) url.openConnection());
        connection.addRequestProperty("User-Agent", "Mozilla/4.0");
        InputStream input;
        input = connection.getInputStream();
       BufferedReader reader = new BufferedReader(new InputStreamReader(input));
        String msg;
        while ((msg = reader.readLine()) != null)
            System.out.println("--------------------"+msg);
       return msg; //html code of the URL
    }
}

爪哇

$scope.htmlResponsedata  = response

以上是我使用angularjs和springMVC编写的整个代码。如何从oe.html页面上的java代码打印msg返回的数据。我使用了{{htmlResponsedata}}但是没有打印响应。 htmlResponsedata是我得到的响应,我在js代码中设置了C:\Users\sdand\Documents\envganagro\templates\login.html (Source does not exist) django.template.loaders.app_directories.Loader: C:\Users\sdand\Documents\envganagro\lib\site-packages\django\contrib\admin\templates\login.html (Source does not exist) django.template.loaders.app_directories.Loader: C:\Users\sdand\Documents\envganagro\lib\site-packages\django\contrib\auth\templates\login.html (Source does not exist) django.template.loaders.app_directories.Loader: C:\Users\sdand\Documents\envganagro\ganagroapp\templates\login.html (Source does not exist) ,如上所示。有关如何在屏幕上打印html响应的任何建议吗?

0 个答案:

没有答案