简体   繁体   English

如何使用/导入要在 HTML 文件(非 JSP)中使用的 Java 区域设置类和资源包属性?

[英]How Do I Use/Import my Java Locale class and Resource Bundle properties to be used in my HTML files (not JSP)?

For my current project, I have a Spring Boot REST service backend using JSON and a set of asynchronous HTML files for the frontend accessing the REST service using AJAX.对于我当前的项目,我有一个使用 JSON 的 Spring Boot REST 服务后端和一组用于使用 AJAX 访问 REST 服务的前端的异步 HTML 文件。 I want to use my Java localization class and my resource bundle properties file for the languages I need which I had created and it worked fine for my previous projects which only used JSP pages.我想将我的 Java 本地化类和我的资源包属性文件用于我创建的我需要的语言,并且它适用于我以前只使用 JSP 页面的项目。

However, for my new project, I am using purely asynchronous HTML files with AJAX (jQuery and vanilla Javascript) and no JSP front-end to connect to my Java backend.但是,对于我的新项目,我使用带有 AJAX(jQuery 和 vanilla Javascript)的纯异步 HTML 文件,没有 JSP 前端连接到我的 Java 后端。 So how do I import and use my Java i18N features in my purely HTML files with AJAX without any JSP?那么如何在没有任何 JSP 的情况下通过 AJAX 在纯 HTML 文件中导入和使用我的 Java i18N 特性?

You cannot have Java code in HTML file.您不能在HTML文件中包含Java代码。 The way it works with JSP is because JSP simply gets compiled to Java Servlets while compilation stage and then they run.它与JSP工作的方式是因为JSP只是在编译阶段被编译成Java Servlets ,然后它们运行。 The best bet to make it work with HTML along with Ajax is, create some kind of meta controller, which provides you the required data related to localization and internationalization in response, and then use it with JavaScript .让它与 HTML 和 Ajax 一起工作的最好办法是,创建某种元控制器,它为您提供与本地化和国际化相关的所需数据作为响应,然后将它与JavaScript一起JavaScript

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM