• 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>

    运行截图:

  • 相关阅读:
    LINUX下文件编译
    Circle HDU
    Tree HDU
    Can you answer these queries? HDU
    Function HDU
    牛客练习赛46 A 华华教奕奕写几何 (简单数学)
    牛客练习赛26 E-树上路径 (树链剖分+线段树)
    Flight HDU
    牛客练习赛47 D DongDong坐飞机 (分层最短路)
    洛谷 P3384 【模板】树链剖分
  • 原文地址:https://www.cnblogs.com/liurg/p/8078578.html
Copyright © 2020-2023  润新知