จะทำให้เนื้อหาอื่น ๆ ของเว็บไซต์ของเราเป็นสากลได้อย่างไร (เช่นเมนูชื่อ ฯลฯ ) นี่คือสิ่งที่บทความนี้ต้องการทำ -> ความเป็นสากล
เนื้อหาที่เพิ่มในไฟล์ Spring.xml ของโครงการมีดังนี้
<MVC: interceptors> <span style = "space สีขาว: pre"> </span> <!-หากการสกัดกั้นการดำเนินการระหว่างประเทศขึ้นอยู่กับ (คำขอ/เซสชัน/คุกกี้) จะต้องกำหนดค่า-> <bean/> </mvc: interceptors>
เพิ่มสามไฟล์ในแหล่งข้อมูลโฟลเดอร์ต้นฉบับในโครงการ: myProperties.properties, myProperties_zh_.properties และ myProperties_en_.properties
นี่คือข้อมูลง่ายๆเกี่ยวกับหน้า JSP เพียงการสาธิตและไม่มีข้อควรพิจารณาอื่น ๆ :
<%@ page language = "java" contentType = "ข้อความ/html; charset = utf-8" pageencoding = "utf-8"%> <! doctype html สาธารณะ "-// w3c // dtd html 4.01 transitional // en" <html> <head> <meta http-equiv = "content-type" content = "text/html; charset = utf-8"> <title> แทรกชื่อที่นี่ </title> </head> <% locale name = (locale) เซสชัน ResourceBundle MyResourcesBundle = ResourceBundle.getBundle ("MyProperties", ชื่อ); %> <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 ("ง่าย")%> </a>รหัสเลเยอร์การกระทำพื้นหลังมีดังนี้:
แพ็คเกจ com.zhidao.oms.index; นำเข้า java.util.locale; นำเข้า javax.servlet.http.httpservletrequest; นำเข้า org.springframework.stereotype.controller; นำเข้า org.springframework.web.bind.annotation.requestmapping; นำเข้า org.springframework.web.bind.annotation.requestparam; @Controller @RequestMapping ("/index") ดัชนีคลาสสาธารณะ {@requestmapping ("/findex") สตริงสาธารณะ findex (httpservletrequest Request, @requestparam String langtype, หน้าสตริง) {ถ้า (langtype.equals ("zh") {locale locale = locale request.getSession (). setAttribute ("i18Nlanguage", locale); } อื่นถ้า (langtype.equals ("en")) {locale locale = locale ใหม่ ("en", "us"); request.getSession (). setAttribute ("i18Nlanguage", locale); } else {request.getSession (). setAttribute ("i18Nlanguage", locale.getDefault ()); } return "/front/"+Page+".jsp"; -เพียงทดสอบการเรนเดอร์ที่เกี่ยวข้อง! ฉันหวังว่าทุกคนจะวิพากษ์วิจารณ์และแก้ไขสิ่งเลวร้ายที่ฉันเขียน
วิธีการสากลข้างต้นตามเซสชันคือเนื้อหาทั้งหมดที่ใช้ร่วมกันโดยตัวแก้ไข ฉันหวังว่ามันจะให้ข้อมูลอ้างอิงและฉันหวังว่าคุณจะสนับสนุน wulin.com มากขึ้น