Bagaimana cara menginternasionalkan konten lain dari situs web kami (seperti menu, judul, dll.)? Inilah yang ingin dibuat oleh artikel ini -> internasionalisasi.
Konten yang ditambahkan dalam file Spring.xml dari proyek ini adalah sebagai berikut
<MVC: Interceptors> <span style = "White-Space: Pre"> </span> <!-Jika pencegat operasi internasional didasarkan pada (permintaan/sesi/cookie), itu harus dikonfigurasi-> <bean/> </mvc: Interceptors>
Tambahkan tiga file dalam sumber daya folder sumber dalam proyek: myproperties.properties, myproperties_zh_.properties, dan myproperties_en_.properties
Berikut adalah beberapa informasi sederhana tentang halaman JSP, hanya demonstrasi dan tidak ada pertimbangan lain:
<%@ page language = "java" contentType = "text/html; charset = utf-8" pageEncoding = "utf-8"%> <! Doctype html public "-// w3c // dtd html 4.01 transisi // en" "http://www.w3.org/org/ht4/t." <html> <head> <meta http-equiv = "konten-tipe" content = "text/html; charset = utf-8"> <itement> Sisipkan judul di sini </iteme> </head> <% name locale = (locale) session.getattribute ("i18nlanguage"); ResourceBundle MyResourcesBundle = ResourceBundle.getBundle ("MyProperties", Name); %> <body> <a href = "$ {pagecontext.request.contextPath} /index/findex.do?langtype=en&page=home"> eng </a> | <a href = "$ {pagecontext.Request.contextPath} /index/findex.do?langtype=zh&page=home"> <%= myResourcesBundle.getString ("disederhanakan")%> </a> </body> </html>Kode Lapisan Latar Belakang adalah sebagai berikut:
paket com.zhidao.oms.index; impor java.util.locale; impor javax.servlet.http.httpservletRequest; impor org.springframework.stereotype.controller; impor org.springframework.web.bind.annotation.requestmapping; impor org.springframework.web.bind.annotation.requestparam; @Controller @RequestMapping ("/index") IndexAction kelas publik {@RequestMapping ("/findex") Public String findex (httpservletRequest, @requestParam string langType, string page) {if (langtype.equals ("zh")) {locale locale = new locale = zh ("zh (" zh "); request.getSession (). setAttribute ("i18nlanguage", locale); } else if (langtype.equals ("en")) {locale locale = new locale ("en", "us"); request.getSession (). setAttribute ("i18nlanguage", locale); } else {request.getSession (). setAttribute ("i18nlanguage", locale.getDefault ()); } return "/front/"+page+".jsp"; }}Cukup uji rendering yang relevan! Saya harap semua orang akan mengkritik dan memperbaiki hal -hal buruk yang saya tulis.
Metode internasionalisasi di atas berdasarkan sesi adalah semua konten yang dibagikan oleh editor. Saya harap ini dapat memberi Anda referensi dan saya harap Anda dapat mendukung wulin.com lebih lanjut.