SpringMVC InternalResourceViewResolver视图解析器

版权声明:最终解释权归属Hern、HernSong(hernsong)、苍鹭、www.hernsong.com所有! https://blog.csdn.net/qq_36761831/article/details/88924110

• JSP 是最常见的视图技术,可以使用 InternalResourceViewResolver 作为视图解析器:

• 若项目中使用了 JSTL,则 SpringMVC 会自动把视图由 InternalResourceView 转为 JstlView

• 若使用 JSTL 的 fmt 标签则需要在 SpringMVC 的配置文件中配置国际化资源文件

<%--
  Created by IntelliJ IDEA.
  User: 23369
  Date: 2019/3/24
  Time: 18:33
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<html>
<head>
    <title>Title</title>
</head>
<body>
<h1>success</h1>
 request 用户信息:${requestScope.userinfo}
<br>
session 用户信息:${sessionScope.userinfo}
<br>
<br>
request 用户信息修改:${requestScope.userinfoModel}
<br>
session 用户信息修改:${sessionScope.userinfoModel}
<br>
<fmt:message key="i18n.username"></fmt:message>
<fmt:message key="i18n.password"></fmt:message>
</body>
</html>
    <bean id="bundleMessageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
        <property name="basename" value="com.propertiesConfig.i18n"></property>
    </bean>

• 若希望直接响应通过 SpringMVC 渲染的页面,可以使用 mvc:viewcontroller 标签实现

<mvc:view-controller path="" view-name=""/>

其中path表示为请求的路径,view-name表示为你需要做的资源操作,其中path会首先匹配requestmapping路径,匹配不到后再进行view-name的资源寻找。view-name中可以输入相对于视图解析器的路径,也可以输入类似于redirect:路径,然后匹配次requestmapping。

当我们配置了<mvc:view-controller />后,原来通过控制器来转发映射的url就无法访问到页面了。通常我们在实际开发中会在配置文件中增加如下配置,解决这个问题。配置后就也可以通过控制器进行转发映射访问,这样就保证我们在开发过程中对出现的各种情况页面进行正常跳转。

<mvc:annotation-driven></mvc:annotation-driven>

猜你喜欢

转载自blog.csdn.net/qq_36761831/article/details/88924110