Javaweb internationalization (used in JSP)

Source: Internet
Author: User
Tags locale

Use the internationalization method in the JSP page, first will jstl the open source Rack package: Jstl.jar,standard.jar leads in

In the SRC directory, a file with the end of the. Properties, starting with Test, is established: test_en_us.properties,test_zh_cn.properties, the file contents are:

Date=date,salary=salary//DATE=\U65E5\U671F,SALARY=\U5DE5\U8D44

<% @pageImport= "Java.util.Locale"%><% @pageImport= "java.util.Date"%><%@ page language= "java" contenttype= "text/html; Charset=utf-8 "pageencoding= "UTF-8"%> <% @taglib prefix= "FMT" uri= "http://java.sun.com/jsp/jstl/fmt"%><% @taglib prefix= "C" uri= " Http://java.sun.com/jsp/jstl/core "%> <! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >Date Date=NewDate (); Request.setattribute ("Date", date); Doublesalary=321321.323; Request.setattribute ("Salary", salary); %> <br><br>Date:<%=date%><br>Salary:<%=salary%> <br><br> <!--use the JSTL tag library to get the capacity in the. properties file that starts with test, and its default value of the Chinese, that is, the Test_zh_cn.properties file, is//Messageformet: Can format module strings, formatdate and Formetnumber ...--<fmt:bundle basename= "Test" > <fmt:message key= "Date" ></fmt:message> <fmt: FormatDate value= "${date}"/> <fmt:message key= "Salary" ></fmt:message> <fmt:formatnumber V Alue= "${salary}" ></fmt:formatNumber> </fmt:bundle> <br><br> <!--dynamic capture, show Chinese and English toggle -<%String Code=request.getparameter ("Code"); if(code!=NULL){            if("en". Equals (code)) {Session.setattribute ("Locale", locale.us); }            Else if("zh". Equals (code)) {Session.setattribute ("Locale", Locale.china); }        }            %> <!--Set the locale within the session to make it easy to get locale-to-<c in the JSP:ifTest= "${sessionscope.locale!=null}" > <fmt:setlocale value= "${sessionscope.locale}"/> </c:if> <fmt:setbundle basename= "Test"/> <fmt:message key= "date" ></fmt:message> <fmt:fo Rmatdate value= "${date}"/> <fmt:message key= "Salary" ></fmt:message> <fmt:formatnumber value= "${sa    Lary} "></fmt:formatNumber> <br><br> <a href=" index.jsp?code=en "> English display </a> <br><br> <a href= "Index.jsp?code=zh" > Chinese display </a> <br><br></body>

Javaweb internationalization (used in JSP)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.