分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 代码编程

jsp页面的国际化

发布时间:2023-09-06 01:42责任编辑:白小东关键词:jsjsp

三个配置文件:

myproperties_en.properties是英文的:

myproperties_zh.properties是中文的:

 jsp页面的代码:

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

<!DOCTYPE HTML>
<html>
?<head>
???<base href="<%=basePath%>"> ???
???<title>国际化(i18n)测试</title>
?</head>
?
?<body>
?<!-- 第一种方式 -->
??<fmt:setBundle basename="property.myproperties" scope="page" ?var="bundle"/>
???<form action="">
????<fmt:message key="username" bundle="${bundle}"/><input type="text" name="username"><br/>
???????<fmt:message key="password" bundle="${bundle}"/><input type="password" name="password"><br/>
???????<input type="submit" value="<fmt:message key="submit" bundle="${bundle}"/>">
???</form>
??<!-- 第二种方式 -->
???<fmt:bundle basename="property.myproperties" >
???<form action="">
???<fmt:message key="username" /><input type="text" name="username"><br/>
???<fmt:message key="password" /><input type="password" name="password"><br/>
???<input type="submit" value="<fmt:message key="submit"/>">
???</form>
???
???</fmt:bundle>
?</body>
</html>

运行结果:

jsp页面的国际化

原文地址:https://www.cnblogs.com/leixia/p/8438730.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved