我无法在spring中将JSP按钮链接到控制器
我试图通过JSP按钮单击将控件传递给控制器。当我点击这个按钮时,它会因为URL的改变而出错。请帮我做同样的事 请参考我的代码,并建议我如何解决我的这个问题 JSP代码:我无法在spring中将JSP按钮链接到控制器,spring,spring-mvc,Spring,Spring Mvc,我试图通过JSP按钮单击将控件传递给控制器。当我点击这个按钮时,它会因为URL的改变而出错。请帮我做同样的事 请参考我的代码,并建议我如何解决我的这个问题 JSP代码: <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transit
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Hello</title>
</head>
<body>
<h2>${message}</h2>
<form method="POST" enctype="multipart/form-data"
action="/upload">
File to upload: <input type="file" name="file"><br /> Name: <input
type="text" name="name"><br /> <br /> <input type="submit"
value="Upload"> Press here to upload the file!
</form>
</body>
</html>
你犯了什么错误?在问题中发布它。现在它正在工作,但我上传文件的访问被拒绝。请告诉我在spring应用程序中更新文件上传路径名的位置
@Controller
@RequestMapping("/")
public class SpringMVController {
@RequestMapping(method = RequestMethod.GET)
public String printHello(ModelMap model) {
model.addAttribute("message", "Hello Spring MVC Framework!");
return "hello";
}
@RequestMapping(value="/upload", method=RequestMethod.POST)
public @ResponseBody String handleFileUpload(@RequestParam("name") String name,
@RequestParam("file") MultipartFile file){
if (!file.isEmpty()) {
try {
byte[] bytes = file.getBytes();
BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream(new File(name)));
stream.write(bytes);
stream.close();
return "You successfully uploaded " + name + "!";
} catch (Exception e) {
return "You failed to upload " + name + " => " + e.getMessage();
}
} else {
return "You failed to upload " + name + " because the file was empty.";
}
}
}