You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This commit refines the JSP view resolver documentation contribution
by using tabs for Java and XML configuration, with Java displayed by
default.
Closesspring-projectsgh-35444
Copy file name to clipboardExpand all lines: framework-docs/modules/ROOT/pages/web/webmvc-view/mvc-jsp.adoc
+18-16Lines changed: 18 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,41 +9,43 @@ The Spring Framework has a built-in integration for using Spring MVC with JSP an
9
9
10
10
When developing with JSPs, you typically declare an `InternalResourceViewResolver` bean.
11
11
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.
14
15
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"]
16
24
----
17
25
@EnableWebMvc
18
26
@Configuration
19
27
public class WebConfig implements WebMvcConfigurer {
20
28
21
29
@Override
22
30
public void configureViewResolvers(ViewResolverRegistry registry) {
23
-
// Use sensible defaults
24
31
registry.jsp();
25
-
// Example of customizing:
26
-
// registry.jsp("/WEB-INF/views/", ".jsp");
27
32
}
28
33
}
29
34
----
30
35
31
-
[NOTE]
32
-
====
33
-
For legacy XML configuration:
34
-
35
-
[source,xml]
36
+
XML::
37
+
+
38
+
[source,xml,indent=0,subs="verbatim,quotes"]
36
39
----
37
40
<mvc:view-resolvers>
38
-
<mvc:jsp prefix="/WEB-INF/jsp/" suffix=".jsp"/>
41
+
<mvc:jsp />
39
42
</mvc:view-resolvers>
40
43
----
44
+
======
41
45
42
-
Prefer JavaConfig for new applications.
43
-
====
46
+
[NOTE]
47
+
You can specify custom prefix and suffix.
44
48
45
-
[.text-muted]
46
-
See the Javadoc of ViewResolverRegistry#jsp() for default prefix and suffix values.
0 commit comments