zoukankan      html  css  js  c++  java
  • SpringMVC(二五) JSTL View

    项目中使用JSTL,SpringMVC会把视图由InternalView转换为JstlView。

    若使用Jstl的fmt标签,需要在SpringMVC的配置文件中配置国际化资源文件。

    实现过程:

    1.引入jstl.jar和standard.jar两个jar文件到classpath中。

    2.在src目录下新建i18n.properties,内容如下:

    i18n.username=Username
    
    i18n.password=Password

    3.复制i18n.properties文件为i18n_zh_CN.properties,内容如下:

    i18n.username=u7528u6237u540D
    i18n.password=u5BC6u7801

    4.复制i18n.properties文件为i18n_en_US.properties,内容如下:

    i18n.username=Username
    i18n.password=Password

    5.在sprinvmvc.xml文件中添加国际化配置文件信息,内容如下:

     View Code

    6.在success.jsp视图文件中添加fmt标签的内容如下:

    复制代码
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html lang="en">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
    </head>
    <body>
        <h1>Hello SpringMVC View</h1>
        time : ${requestScope.time} 
        <br>
        <fmt:message key="i18n.username"></fmt:message>
        <br>
        <fmt:message key="i18n.password"></fmt:message>
    
    
         <script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>
    </body>
    </html>
    复制代码

    目录结构如下图:

    测试视图index.jsp

        <a href="helloworld">Hello World</a>

    测试控制器代码:

    复制代码
    package com.tiekui.springmvc.handlers;
    
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    
    @Controller
    public class HelloWorld {
        
        @RequestMapping("/helloworld")
        public String hello(){
            System.out.println("hello world");
            return "success";
        }
        
    
    }
    复制代码

    测试方法:

    1) 初次将IE浏览器首选语言设置为中文

    2)将IE浏览器的首先语言优先级调整为英文优先。

    注意事项:如果发现返回的中文有乱码,需要将success.jsp的编码设置为UTF-8。

    https://github.com/godmaybelieve
  • 相关阅读:
    [转载]安装SQL Server 2008 R2遇到“...Setup has stopped working.”
    WPF验证错误显示
    说一下我对Mvvm模式的理解
    [转载]C#深拷贝的方法
    Windows Phone 开发(一):入门指南 — 安装开发环境:Windows Phone SDK
    DateTime.ToString() Patterns
    Log4net 根据日志类别保存到不同的文件,并按照日期生成不同文件名称
    使用Visual Studio 2010进行UI自动化测试
    WPF触发器之数据触发器(A)
    Getting The imported project "C:\Program Files\MSBuild\Microsoft\Silverlight for Phone\v4.0\Microsoft.Silverlight..Overrides.targets" was not found
  • 原文地址:https://www.cnblogs.com/yuyu666/p/10136117.html
Copyright © 2011-2022 走看看