Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 31 additions & 9 deletions framework-docs/modules/ROOT/pages/web/webmvc-view/mvc-jsp.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down