[英]Why am I getting Bad Request kind error when uploading file using jquery with spring mvc?
[英]Java Spring MVC - Uploading and storing file inside “webapp” folder is bad idea? Why is it?
在Spring MVC中上傳文件時,我發現許多文章建議您將其存儲在文件系統文件夾中,而不是項目內部的文件夾中。
但是我的網絡應用使用webapp文件夾內的文件夾中的文件來呈現HTML(視圖)頁面。
├── src
│ ├── main
│ │ ├── java
│ │ │ └── com // Where my application's is.
│ │ ├── resources
│ │ │ ├── META-INF
│ │ │ ├── log4j.xml
│ │ │ ├── maildata.properties
│ │ │ └── persistence-mysql.properties
│ │ └── webapp
│ │ ├── WEB-INF
│ │ │ ├── classes
│ │ │ ├── spring
│ │ │ ├── templates // Where my view pages are. Thymeleaf template used.
│ │ │ │ ├── login.html
│ │ │ │ ├── index.html
│ │ │ │ └── ...html and More...
│ │ │ └── web.xml
│ │ └── resources // --> This is location that my app use for rendering.
│ │ ├── css
│ │ ├── fonts
│ │ ├── images
│ │ ├── js
│ │ └── vendors
│ └── test
│ ├── java
│ │ └── com
│ └── resources
│ └── log4j.xml
└── target
在“視圖”部分中,我使用資源文件夾中的文件來呈現HTML頁面。
.
.
<link rel="stylesheet" th:href="@{'/resources/css/style.css'}" type="text/css">
.
.
.outbox {
background:
url([[@{/resources/images/header.jpg}]]) #000
55% 0 no-repeat;
background-size: 140% auto;
margin-top: -68px;
width: 100%;
padding-top: 42.25%;
position: relative;
display: block;
z-index: -1;
}
.
.
.
我要提供將文件上傳到資源文件夾並用於呈現HTML頁面的功能。
這是一個壞主意嗎? 你能解釋為什么嗎?
如果是這樣,我可以為自己的任務采取的最佳方法是什么? (用於上傳文件的最佳位置)
如果取消部署該應用程序,上傳到資源文件夾的所有文件將如何處理? 我相信它們會與應用程序的其余部分一起刪除。 如果這對您來說無關緊要,那么可以直接上傳到該行。 相反,如果您希望文件在部署之間持久存在,則應該:
無論哪種情況,您都需要一個控制器來將圖像作為文件返回(因為它們不再可以作為資源訪問)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.