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

    运行截图:

  • 相关阅读:
    今天18:40分左右一部价值500多块捷安特自行车被盗!
    利用ASP.net上传文件
    _desktop.ini
    Visual Studio .NET 设置移植工具
    审计厅的项目终于可以告一段落了
    Word2CHM Assistant(Word2CHM助手)V2.1.0 破解版
    最近比较烦!
    delphi 中 Format 用法总汇
    谈谈公司管理及需求方面的问题
    [待续]SQLSERVER无法访问远程服务器问题
  • 原文地址:https://www.cnblogs.com/liurg/p/8078578.html
Copyright © 2020-2023  润新知