Browse Source

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
pull/35428/head
Sébastien Deleuze 3 months ago
parent
commit
dff489d0cf
  1. 34
      framework-docs/modules/ROOT/pages/web/webmvc-view/mvc-jsp.adoc

34
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. 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. `InternalResourceViewResolver` can be used for dispatching to any Servlet resource but in
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. 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 @EnableWebMvc
@Configuration @Configuration
@ -20,30 +28,24 @@ public class WebConfig implements WebMvcConfigurer {
@Override @Override
public void configureViewResolvers(ViewResolverRegistry registry) { public void configureViewResolvers(ViewResolverRegistry registry) {
// Use sensible defaults
registry.jsp(); registry.jsp();
// Example of customizing:
// registry.jsp("/WEB-INF/views/", ".jsp");
} }
} }
---- ----
[NOTE] XML::
==== +
For legacy XML configuration: [source,xml,indent=0,subs="verbatim,quotes"]
[source,xml]
---- ----
<mvc:view-resolvers> <mvc:view-resolvers>
<mvc:jsp prefix="/WEB-INF/jsp/" suffix=".jsp"/> <mvc:jsp />
</mvc:view-resolvers> </mvc:view-resolvers>
---- ----
======
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]] [[mvc-view-jsp-jstl]]
== JSPs versus JSTL == JSPs versus JSTL

Loading…
Cancel
Save