From dff489d0cf4f79d48eed9fc1b930030fd7fd94e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Deleuze?= Date: Tue, 9 Sep 2025 13:23:16 +0200 Subject: [PATCH] Refine JSP documentation contribution This commit refines the JSP view resolver documentation contribution by using tabs for Java and XML configuration, with Java displayed by default. Closes gh-35444 --- .../ROOT/pages/web/webmvc-view/mvc-jsp.adoc | 34 ++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/framework-docs/modules/ROOT/pages/web/webmvc-view/mvc-jsp.adoc b/framework-docs/modules/ROOT/pages/web/webmvc-view/mvc-jsp.adoc index 920081c0b78..646684464e0 100644 --- a/framework-docs/modules/ROOT/pages/web/webmvc-view/mvc-jsp.adoc +++ b/framework-docs/modules/ROOT/pages/web/webmvc-view/mvc-jsp.adoc @@ -9,10 +9,18 @@ The Spring Framework has a built-in integration for using Spring MVC with JSP an When developing with JSPs, you typically declare an `InternalResourceViewResolver` bean. -`InternalResourceViewResolver` can be used for dispatching to any Servlet resource but in particular for JSPs. -As a best practice, we strongly encourage placing your JSP files in a directory under the `WEB-INF` directory so there can be no direct access by clients. +`InternalResourceViewResolver` can be used for dispatching to any Servlet resource but in +particular for JSPs. As a best practice, we strongly encourage placing your JSP files in +a directory under the `WEB-INF` directory so there can be no direct access by clients. -[source,java] +This is what is done by the configuration below which registers a JSP view resolver using +a default view name prefix of `"/WEB-INF/"` and a default suffix of `".jsp"`. + +[tabs] +====== +Java:: ++ +[source,java,indent=0,subs="verbatim,quotes"] ---- @EnableWebMvc @Configuration @@ -20,30 +28,24 @@ public class WebConfig implements WebMvcConfigurer { @Override public void configureViewResolvers(ViewResolverRegistry registry) { - // Use sensible defaults registry.jsp(); - // Example of customizing: - // registry.jsp("/WEB-INF/views/", ".jsp"); } } ---- -[NOTE] -==== -For legacy XML configuration: - -[source,xml] +XML:: ++ +[source,xml,indent=0,subs="verbatim,quotes"] ---- - + ---- +====== -Prefer JavaConfig for new applications. -==== +[NOTE] +You can specify custom prefix and suffix. -[.text-muted] -See the Javadoc of ViewResolverRegistry#jsp() for default prefix and suffix values. [[mvc-view-jsp-jstl]] == JSPs versus JSTL