[英]How to pass a null value for a URL parameter to Spring MVC controller?
[英]How to pass URL as parameter in Spring mvc
我正在尝试通过按钮提交将URL从jsp传递到控制器
JSP代码:
<input type="button" onClick="window.location='<c:url value="/tools/serverLogs/${logsPath}/"/>'" name="serverLogsPage" value="View all logs"/>
控制器:
@RequestMapping(value="/tools/serverLogs/{logsPath}",method=RequestMethod.GET)
public String showLogs( Model m, @PathVariable String logsPath) {
return "tools/ServerLogs";
}
我尝试以不同的格式传递路径,但是在转到控制器时出现错误。
例:
logsPath =“ C:\\ abc \\ def \\ ght”;
logsPath =“ C:\\ abc \\ def \\ ght”(在这种情况下,我没有收到任何错误,但是在控制器中,路径看起来像C:abc def ght);
logsPath =“ C:// abc // def // ght”;
logsPath =“ file:// abc / def / ght”;
您可以在将logsPath传递给视图之前对其进行编码,并在检索内容时对其进行解码
logsPath = "C:\abc\def\ght";
logsPath = URLEncoder.encode(logsPath, "UTF-8"); // Or "ISO-8859-1"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.