问题描述
我正在尝试通过按钮提交将jsp的URL传递给控制器
I am trying to pass an URL from jsp to controller on a button submit
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";
}
我尝试以不同的格式传递路径,但是在转到控制器时出现错误.
I tried passing the path in different formats, but i am getting error while going to the controller.
示例:
logsPath ="C:\ abc \ def \ ght";
logsPath = "C:\abc\def\ght";
logsPath ="C:\ abc \ def \ ght"(在这种情况下,我没有收到任何错误,但在控制器中,路径看起来像C:abc def ght);
logsPath = "C:\abc\def\ght" (In this case i am not getting any error but in controller the path looks like C: abc def ght);
logsPath ="C://abc//def//ght";
logsPath = "C://abc//def//ght";
logsPath ="file://abc/def/ght";
logsPath = "file://abc/def/ght";
推荐答案
您可以在将logsPath传递给视图之前对其进行编码,并在检索内容时对其进行解码
You could encode the logsPath before passing it on the view and decode it when retrieving content
logsPath = "C:\abc\def\ght";
logsPath = URLEncoder.encode(logsPath, "UTF-8"); // Or "ISO-8859-1"
这篇关于如何在Spring MVC中将URL作为参数传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!