SpringMVC学习五

view-controller

配置直接转发的页面,在配置文件中:

 

<!-- 配置直接转发的页面 -->
           <mvc:view-controller path="/success" view-name="success" />

 

在运行时控制台报错:

 

 org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'mvc:view-controller'.

这是因为写约束时的mvc没有写进去

<beans xmlns="http://www.springframework.org/schema/beans"
 
         xmlns:aop="http://www.springframework.org/schema/aop"
 
       xmlns:mvc="http://www.springframework.org/schema/mvc"
 
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 
       xmlns:context="http://www.springframework.org/schema/context" 
 
       xmlns:p="http://www.springframework.org/schema/p"
       
       xmlns:tx="http://www.springframework.org/schema/tx"
 
  xsi:schemaLocation="
 
              http://www.springframework.org/schema/beans    
 
                 http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
     
              http://www.springframework.org/schema/tx      
 
              http://www.springframework.org/schema/tx/spring-mvc-4.0.xsd
 
               http://www.springframework.org/schema/context
 
               http://www.springframework.org/schema/context/spring-context-4.0.xsd
               
               http://www.springframework.org/schema/mvc
               
               http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
 
               http://www.springframework.org/schema/aop
 
             http://www.springframework.org/schema/aop/spring-aop-4.0.xsd">

 

 

<!-- 在实际开发中通常都需要配置mvc:annotation-driven标签 
               因为加上mvc:view-controller后以前的@RequestMapping不起作用-->
            <mvc:annotation-driven></mvc:annotation-driven>

 

运行代码success.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"  isErrorPage="true"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'success.jsp' starting page</title>
    
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->

  </head>
  
  <body>
   success page. <br>
   time: ${requestScope.time}
   <br>
   names: ${requestScope.names}
   <br>
   Request user: ${requestScope.user}
   <br>
  Session  user: ${sessionScope.user}
  <br>
  <fmt:message key="i18n.username"></fmt:message>
  <br>
  <fmt:message key="i18n.password"></fmt:message>
  
  </body>
</html>

 

运行截图:

 

posted @ 2017-12-21 13:40  蓉啊  阅读(187)  评论(0编辑  收藏  举报