春季启动Web应用程序带有JSP文件扩展名中的url中的JSP文件扩展名

发布于 2025-02-13 08:52:32 字数 2399 浏览 0 评论 0原文

我们有一个传统的Web应用程序,该应用程序使用以下URL:

https://example.com/forms/forms.jsp

我们已重写了旧的代码,以使用url 使用Spring Boot Web应用程序https://example.com/forms.jsp在URL中扩展。

为了保留旧的URL(这是业务要求),我遵循此 spring mvc @用点(。)的路径变量被截断。但是,它仅在URL中的/ 时起作用。

我搜索了它,在堆栈溢出中发现了一些建议,并尝试了几种不同的方法。但不太努力。

更新:

我刚刚找到 a>。我从@getMapping(“/forms/{jspname:。+}”) @getMapping(path =“/forms/forms/{jspname:。+}”)> 。这使得可以在if语句中检查路径变量。但是,返回语句不会像以前一样返回预期forms.jsp文件;相反,它给出了404错误。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

热情消退 2025-02-20 08:52:32

由于此应用仅用于培训,因此我将JSP文件移至webApp/forms.forms.forms.jsp文件夹。这样,可以直接从下面的URL访问JSP文件:

https://example.com/forms/forms.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:

https://example.com/forms/forms.jsp

There is no need to go through a controller. Thanks to my friend Barry for his suggestion. Thanks!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文