修改了资源访问和controller映射路径。
修改了临时文件目录。
This commit is contained in:
parent
c41bcc6a35
commit
a26d1b5203
@ -8,6 +8,7 @@
|
|||||||
{
|
{
|
||||||
"label": "off"
|
"label": "off"
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
"no-inline-styles": "off"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,7 +2,7 @@
|
|||||||
* @Author: Kane
|
* @Author: Kane
|
||||||
* @Date: 2022-09-28 15:47:02
|
* @Date: 2022-09-28 15:47:02
|
||||||
* @LastEditors: Kane
|
* @LastEditors: Kane
|
||||||
* @LastEditTime: 2022-09-30 00:33:41
|
* @LastEditTime: 2022-09-30 10:45:27
|
||||||
* @FilePath: \car_dealer\src\main\java\com\cpic\xim\car_dealer\controllers\fileupload\FileUploadController.java
|
* @FilePath: \car_dealer\src\main\java\com\cpic\xim\car_dealer\controllers\fileupload\FileUploadController.java
|
||||||
* @Description:
|
* @Description:
|
||||||
*
|
*
|
||||||
@ -26,9 +26,10 @@ import org.springframework.web.multipart.MultipartFile;
|
|||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
@Scope( "session")
|
@Scope( "session")
|
||||||
|
@RequestMapping( path = "/upload")
|
||||||
public class FileUploadController
|
public class FileUploadController
|
||||||
{
|
{
|
||||||
@RequestMapping( value = "/test" )
|
@RequestMapping( value = "/test.do")
|
||||||
public void test() throws ServletException, IOException
|
public void test() throws ServletException, IOException
|
||||||
{
|
{
|
||||||
// PrintWriter writer = response.getWriter();
|
// PrintWriter writer = response.getWriter();
|
||||||
@ -42,16 +43,18 @@ public class FileUploadController
|
|||||||
* @param uploadFile
|
* @param uploadFile
|
||||||
* @return FileUploadResult
|
* @return FileUploadResult
|
||||||
*****************************************************/
|
*****************************************************/
|
||||||
@RequestMapping( path = "/upload" )
|
@RequestMapping( path = "/upload_file.do")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
@CrossOrigin
|
@CrossOrigin
|
||||||
public FileUploadResult uploadFile( HttpServletRequest request, MultipartFile uploadFile,
|
public FileUploadResult uploadFile( HttpServletRequest request, HttpServletResponse response,
|
||||||
String test ) throws IllegalSelectorException, IOException
|
MultipartFile uploadFile, String test ) throws IllegalSelectorException, IOException
|
||||||
{
|
{
|
||||||
// response.setContentType( "text/json;charset=UTF-8" );
|
// response.setContentType( "text/json;charset=UTF-8" );
|
||||||
// response.setHeader( "Access-Control-Allow-Origin", "*" );
|
// response.setHeader( "Access-Control-Allow-Origin", "*" );
|
||||||
// response.setHeader( "Access-Control-Allow-Methods", "GET,POST" );
|
// response.setHeader( "Access-Control-Allow-Methods", "GET,POST" );
|
||||||
|
|
||||||
|
request.getCookies();
|
||||||
|
|
||||||
FileUploadResult result = new FileUploadResult();
|
FileUploadResult result = new FileUploadResult();
|
||||||
String sessionID = request.getSession().getId();
|
String sessionID = request.getSession().getId();
|
||||||
|
|
||||||
@ -72,7 +75,7 @@ public class FileUploadController
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 使用sessionID来作为存放的目录
|
// 使用sessionID来作为存放的目录
|
||||||
String rootPath = request.getServletContext().getRealPath( "/" + sessionID );
|
String rootPath = request.getServletContext().getRealPath( "/temp/upload/" + sessionID );
|
||||||
String fileName = uploadFile.getOriginalFilename();
|
String fileName = uploadFile.getOriginalFilename();
|
||||||
|
|
||||||
File destFile = new File( rootPath, fileName );
|
File destFile = new File( rootPath, fileName );
|
||||||
|
@ -19,8 +19,8 @@
|
|||||||
</bean> -->
|
</bean> -->
|
||||||
|
|
||||||
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
|
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
|
||||||
<!-- <property name="defaultEncoding" value="UTF-8" /> -->
|
<property name="defaultEncoding" value="UTF-8" />
|
||||||
<property name="maxUploadSize" value="5000000" />
|
<property name="maxUploadSize" value="-1" />
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
</beans>
|
</beans>
|
@ -15,7 +15,7 @@
|
|||||||
</servlet>
|
</servlet>
|
||||||
<servlet-mapping>
|
<servlet-mapping>
|
||||||
<servlet-name>springmvc</servlet-name>
|
<servlet-name>springmvc</servlet-name>
|
||||||
<url-pattern>/</url-pattern>
|
<url-pattern>*.do</url-pattern>
|
||||||
</servlet-mapping>
|
</servlet-mapping>
|
||||||
|
|
||||||
</web-app>
|
</web-app>
|
@ -2,7 +2,7 @@
|
|||||||
* @Author: Kane
|
* @Author: Kane
|
||||||
* @Date: 2022-09-29 16:33:30
|
* @Date: 2022-09-29 16:33:30
|
||||||
* @LastEditors: Kane
|
* @LastEditors: Kane
|
||||||
* @LastEditTime: 2022-09-30 00:33:12
|
* @LastEditTime: 2022-09-30 10:26:34
|
||||||
* @FilePath: \car_dealer\src\main\webapp\file_upload.html
|
* @FilePath: \car_dealer\src\main\webapp\file_upload.html
|
||||||
* @Description:
|
* @Description:
|
||||||
*
|
*
|
||||||
@ -22,7 +22,7 @@
|
|||||||
<body>
|
<body>
|
||||||
<div id="app">
|
<div id="app">
|
||||||
<form
|
<form
|
||||||
action="http://localhost:8080/cardealer/upload"
|
action="http://localhost:8080/cardealer/upload.do"
|
||||||
id="uploadform"
|
id="uploadform"
|
||||||
enctype="multipart/form-data"
|
enctype="multipart/form-data"
|
||||||
method="post"
|
method="post"
|
||||||
@ -51,7 +51,8 @@
|
|||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
<script>
|
<script>
|
||||||
const reqeustURL = "http://localhost:8080/cardealer/upload";
|
const reqeustURL =
|
||||||
|
"http://localhost:8080/cardealer/upload/upload_file.do";
|
||||||
const btnUpload = document.getElementById("btnUpload");
|
const btnUpload = document.getElementById("btnUpload");
|
||||||
|
|
||||||
function fileUploadChange() {
|
function fileUploadChange() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user