如何从applet的要求设置Accept-Language头applet、Accept、Language

2023-09-07 08:45:02 作者:幸好时光与你同在

我不熟悉Java,但我需要从我的小应用程序内发出请求到远程web服务。

web服务(.NET 1.1)使用 HttpContext.Current.Request.UserLanguages​​ [0] 来确定要使用的语言。但这个成员的值常是空。

那么,有没有办法通过Accept-Language头以及类似EN-GB设置?

解决方案

如果这是不够好,你知道的小应用程序运行的系统的默认语言(操作系统),可以从小程序#的getLocale()。如果你真的需要preferred浏览器语言,你可以得到它的服务器端的Servlet容器从的ServletRequest#的getLocale()和动态生成的小程序标签,传递语言code的小程序作为参数。

I'm not familiar with Java but I need to make a request to a remote webservice from within my applet.

如何修改Firefox的Accept Language值

The webservice (.Net 1.1) uses HttpContext.Current.Request.UserLanguages[0] to determine the language to use. But the value of this member is alway null.

So is there a way to pass the Accept-Language header along with something like "en-GB" set?

解决方案

If it is good enough for you to know the default language (operating system) of the system the applet is running, you can get it from Applet#getLocale(). If you really need the preferred browser language, you can get it server-side in a servlet container from ServletRequest#getLocale() and generate the applet tag dynamically, passing the language code to the applet as a parameter.