Skip to content

Commit dff489d

Browse files
committed
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 spring-projectsgh-35444
1 parent 1abd1d7 commit dff489d

File tree

1 file changed

+18
-16
lines changed
  • framework-docs/modules/ROOT/pages/web/webmvc-view

1 file changed

+18
-16
lines changed

framework-docs/modules/ROOT/pages/web/webmvc-view/mvc-jsp.adoc

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,41 +9,43 @@ The Spring Framework has a built-in integration for using Spring MVC with JSP an
99

1010
When developing with JSPs, you typically declare an `InternalResourceViewResolver` bean.
1111

12-
`InternalResourceViewResolver` can be used for dispatching to any Servlet resource but in particular for JSPs.
13-
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.
12+
`InternalResourceViewResolver` can be used for dispatching to any Servlet resource but in
13+
particular for JSPs. As a best practice, we strongly encourage placing your JSP files in
14+
a directory under the `WEB-INF` directory so there can be no direct access by clients.
1415

15-
[source,java]
16+
This is what is done by the configuration below which registers a JSP view resolver using
17+
a default view name prefix of `"/WEB-INF/"` and a default suffix of `".jsp"`.
18+
19+
[tabs]
20+
======
21+
Java::
22+
+
23+
[source,java,indent=0,subs="verbatim,quotes"]
1624
----
1725
@EnableWebMvc
1826
@Configuration
1927
public class WebConfig implements WebMvcConfigurer {
2028
2129
@Override
2230
public void configureViewResolvers(ViewResolverRegistry registry) {
23-
// Use sensible defaults
2431
registry.jsp();
25-
// Example of customizing:
26-
// registry.jsp("/WEB-INF/views/", ".jsp");
2732
}
2833
}
2934
----
3035
31-
[NOTE]
32-
====
33-
For legacy XML configuration:
34-
35-
[source,xml]
36+
XML::
37+
+
38+
[source,xml,indent=0,subs="verbatim,quotes"]
3639
----
3740
<mvc:view-resolvers>
38-
<mvc:jsp prefix="/WEB-INF/jsp/" suffix=".jsp"/>
41+
<mvc:jsp />
3942
</mvc:view-resolvers>
4043
----
44+
======
4145

42-
Prefer JavaConfig for new applications.
43-
====
46+
[NOTE]
47+
You can specify custom prefix and suffix.
4448

45-
[.text-muted]
46-
See the Javadoc of ViewResolverRegistry#jsp() for default prefix and suffix values.
4749

4850
[[mvc-view-jsp-jstl]]
4951
== JSPs versus JSTL

0 commit comments

Comments
 (0)