Update mvc-jsp.adoc

See gh-35444
Signed-off-by: DongNyoung Lee <121621378+Dongnyoung@users.noreply.github.com>
This commit is contained in:
DongNyoung Lee 2025-09-08 22:11:15 +09:00 committed by Sébastien Deleuze
parent 7baf6d12b0
commit 1abd1d767d
1 changed files with 31 additions and 9 deletions

View File

@ -9,19 +9,41 @@ 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,xml,indent=0,subs="verbatim,quotes"]
[source,java]
----
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
@EnableWebMvc
@Configuration
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]
----
<mvc:view-resolvers>
<mvc:jsp prefix="/WEB-INF/jsp/" suffix=".jsp"/>
</mvc:view-resolvers>
----
Prefer JavaConfig for new applications.
====
[.text-muted]
See the Javadoc of ViewResolverRegistry#jsp() for default prefix and suffix values.
[[mvc-view-jsp-jstl]]
== JSPs versus JSTL