春季启动Web应用程序带有JSP文件扩展名中的url中的JSP文件扩展名
我们有一个传统的Web应用程序,该应用程序使用以下URL:
https://example.com/forms/forms.jsp
我们已重写了旧的代码,以使用url 使用Spring Boot Web应用程序https://example.com/forms
不.jsp
在URL中扩展。
为了保留旧的URL(这是业务要求),我遵循此 spring mvc @用点(。)的路径变量被截断。但是,它仅在URL中的/
时起作用。
我搜索了它,在堆栈溢出中发现了一些建议,并尝试了几种不同的方法。但不太努力。
更新:
URL:http:// localhost:8080/forms/forms/forms.jsp
@GetMapping(path = "/forms/{jspName:.+}")
public String getForms(@PathVariable("jspName") String jspName) {
if (jspName.equalsIgnoreCase("forms.jsp")) {
log.debug("JSP file is {}", jspName);
return "forms";
}
return "index";
}
console:
[nio-8080-exec-1] c.n.e.c.EthicsEmailFormController : JSP file is forms.jsp
404错误:
No webpage was found for the web address: http://localhost:8080/forms/forms.jsp
HTTP ERROR 404
application.properties- forms.jsp
存储在/web>/web -inf/views/page/page/page/page/ forms.jsp
。
spring.mvc.view.prefix=/WEB-INF/views/page/
spring.mvc.view.suffix=.jsp
要进行比较:
下面有效,当URL为https://example.com/forms/forms/forms.jsp/
带有/
在URL结束时。但是现有的URL(在要求中指定)在URL末尾不包含/
。它必须是https://example.com/forms/forms.jsp
。
@GetMapping("/forms/{jspName:.+}")
public String getForms(@PathVariable("jspName") String jspName) {
log.debug("Jsp file name = {} ", jspName);
return "forms";
}
我看到一些建议是删除以下依赖关系。我在pom.xml
中也没有以下依赖关系。
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
有什么建议吗?多谢!
We have a legacy web app that uses the url below:
https://example.com/forms/forms.jsp
We have rewritten the legacy code to use spring boot web app with the url https://example.com/forms
without .jsp
extension in the url.
In order to keep the old url, which is a business requirement, I followed this Spring MVC @PathVariable with a dot (.) gets truncated. However, it only works when there is a /
https://example.com/forms/forms.jsp/
in the url.
I googled it, found some suggestions in stack overflow and tried a couple of different approaches. But not quite working.
UPDATES:
I just found this post on jsp in the url. I updated from @GetMapping("/forms/{jspName:.+}")
to @GetMapping(path = "/forms/{jspName:.+}")
. This made it possible to check the pathVariable in the if statement. However, the return
statement does not return the expected forms.jsp
file as before; instead it gives 404
error.
url : http://localhost:8080/forms/forms.jsp
@GetMapping(path = "/forms/{jspName:.+}")
public String getForms(@PathVariable("jspName") String jspName) {
if (jspName.equalsIgnoreCase("forms.jsp")) {
log.debug("JSP file is {}", jspName);
return "forms";
}
return "index";
}
Console:
[nio-8080-exec-1] c.n.e.c.EthicsEmailFormController : JSP file is forms.jsp
404 Error:
No webpage was found for the web address: http://localhost:8080/forms/forms.jsp
HTTP ERROR 404
application.properties - The forms.jsp
is stored under /WEB-INF/views/page/forms.jsp
.
spring.mvc.view.prefix=/WEB-INF/views/page/
spring.mvc.view.suffix=.jsp
For comparison:
Below works when the url is https://example.com/forms/forms.jsp/
with a /
at the end of the url. But the existing url (that is specified in the requirement) does not contain a /
at the end of the url. It has to be https://example.com/forms/forms.jsp
.
@GetMapping("/forms/{jspName:.+}")
public String getForms(@PathVariable("jspName") String jspName) {
log.debug("Jsp file name = {} ", jspName);
return "forms";
}
I saw some suggestion is to remove below dependency. I also do NOT have below dependency in pom.xml
.
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
Any suggestions? Thanks a lot!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于此应用仅用于培训,因此我将JSP文件移至
webApp/forms.forms.forms.jsp
文件夹。这样,可以直接从下面的URL访问JSP文件:无需通过控制器。感谢我的朋友巴里的建议。谢谢!
Since this app is for training only, I moved the jsp file to
webapp/forms.forms.jsp
folder. This way, the jsp file can be accessed directly from the url below:There is no need to go through a controller. Thanks to my friend Barry for his suggestion. Thanks!