Skip to content

Commit 6e9553a

Browse files
authored
Update mvc-jsp.adoc
Signed-off-by: DongNyoung Lee <[email protected]>
1 parent ec4390b commit 6e9553a

File tree

1 file changed

+31
-9
lines changed
  • framework-docs/modules/ROOT/pages/web/webmvc-view

1 file changed

+31
-9
lines changed

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

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,41 @@ 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
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.
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.
1514

16-
[source,xml,indent=0,subs="verbatim,quotes"]
15+
[source,java]
1716
----
18-
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
19-
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
20-
<property name="prefix" value="/WEB-INF/jsp/"/>
21-
<property name="suffix" value=".jsp"/>
22-
</bean>
17+
@EnableWebMvc
18+
@Configuration
19+
public class WebConfig implements WebMvcConfigurer {
20+
21+
@Override
22+
public void configureViewResolvers(ViewResolverRegistry registry) {
23+
// Use sensible defaults
24+
registry.jsp();
25+
// Example of customizing:
26+
// registry.jsp("/WEB-INF/views/", ".jsp");
27+
}
28+
}
2329
----
2430

31+
[NOTE]
32+
====
33+
For legacy XML configuration:
34+
35+
[source,xml]
36+
----
37+
<mvc:view-resolvers>
38+
<mvc:jsp prefix="/WEB-INF/jsp/" suffix=".jsp"/>
39+
</mvc:view-resolvers>
40+
----
41+
42+
Prefer JavaConfig for new applications.
43+
====
44+
45+
[.text-muted]
46+
See the Javadoc of {api-docs}/org/springframework/web/servlet/config/annotation/ViewResolverRegistry.html#jsp() for defaults.
2547

2648
[[mvc-view-jsp-jstl]]
2749
== JSPs versus JSTL

0 commit comments

Comments
 (0)