国际化和登录过滤和类型转换器

本文介绍了在Java Struts框架中实现国际化、登录拦截器的配置和使用,以及如何处理类型转换问题。通过XML配置、属性文件、登录界面和拦截器逻辑展示了登录拦截的完整流程。此外,还讲解了当请求参数类型与实体类属性不匹配时,如何通过注解和自定义类型转换器进行转换。
摘要由CSDN通过智能技术生成

国际化

:它们分别是“语言类型”和“国家/地区的类型”。
简单的写有一个例子:
xml配置:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans 
	http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/context 
		http://www.springframework.org/schema/context/spring-context-4.3.xsd http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd">
        <context:component-scan base-package="gvn.openlab"></context:component-scan>
    <mvc:annotation-driven/>
        <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">

        <property name="prefix" value="/WEB-INF/views/"></property>
        <property name="suffix" value=".jsp"></property>

</bean>
    <mvc:view-controller path="/" view-name="index"></mvc:view-controller>
    <mvc:view-controller path="/save" view-name="save"></mvc:view-controller>
    <mvc:view-controller path="/logn" view-name="logn"></mvc:view-controller>
    <!--获取资源文件il8n的内容-->
<bean class="org.springframework.context.support.ResourceBundleMessageSource" id="messageSource">
    <property name="defaultEncoding" value="UTF-8"></property>
<property name="basename" value="il8n"></property>
</bean>
<!--判断locale,采用HTTP请求的Accept-Language-->
    <bean class="org.springframework.web.servlet.i18n.SessionLocaleResolver" id="localeResolver">
    </bean>
    <mvc:interceptors>
    <!--LocaleChangeInterceptor spring动态改变本地语言-->
        <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"></bean>

    </mvc:interceptors>
</beans>

il8n_en_US.properties和il8n_zh_CN.properties文件

il8n.name:English
il8n.name:汉语

展示jsp文件:

<%--
  Created by IntelliJ IDEA.
  User: 11960
  Date: 2021/9/21
  Time: 16:31
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
//JSTL标签提供了对国际化(I18N)的支持,它可以根据发出请求的客户端地域的不同来显示不同的语言。同时还提供了格式化数据和日期的方法。实现这些功能需要I18N格式标签库(I18N-capable formation tags liberary)。引入该标签库的方法为:
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
//I18N格式标签库提供了11个标签,这些 标签从功能上可以划分为3类如下:
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<html>
<head>
    <title>Title</title>
</head>
<body>
<a href="${pageContext.request.contextPath}/emp">查看信息<
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值