我從spring控制器發送文件路徑和文件名到html頁面。 (即,從彈簧控制器向js控制器發送D:/dataStacks/myStacks/myFilename.txt
)。 我想顯示文件的完整路徑以及網頁上的文件名。 請指教如何打印只返回到JS控制器FILEPATH響應對象的文件名。任何建議將有所幫助。如何在HTML頁面中只打印響應對象的一部分
JS控制器:
myApp.controller('getPathController', function ($scope, MyFilesService) {
$scope.getFilePathAndName = function() {
MyFilesService.getFiles().then(
function (response) {
$scope.filePathAndName = response; // c:/dataStacks/myStacks/myFilename.txt
},
function (errResponse) {
//error
});
}
$scope.getFilePathAndName();
});
//service call
myFilesService.getFiles = function() {
var Url = myURL + '/filesPathData/getFilePath.form';
$http.get(repUrl).then(
function (response) {
//return response
}
//return statement
}
春天控制器:
@RequestMapping(value = "/getFilePath", method = RequestMethod.GET,produces="text/plain")
public @ResponseBody String getFilePath1(HttpServletRequest request) throws Exception {
String FILEPATH = "c:/dataStacks/myStacks/myFilename.txt";
File f = new File(FILEPATH);
//logic to deal with the file
return FILEPATH;
}
HTML:
<html>
<body>
FilePath with filename : {{filePathAndName}} //logic implementation //print only the filename from above got response object
<h1>FileName here</h1>
</body>
</html>
在我的HTML頁我想打印從響應對象所採取的文件名。 {{filePathAndName}}
包含D:/dataStacks/myStacks/myFilename.txt
。如何在HTML頁面中只打印文件名myFilename.txt
。
你可以使用字符串分割功能。 – Jenny