How to set Accept-Language header on request from applet

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

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.


Ok I assume you do something like this in the applet

URL url = new URL("");
URLConnection urlconn = url.openConnection();

Then just set the Accept-Language header before you do the real request

//Assuming you know the language parameter you want to pass along you
urlconnection.setRequestProperty("Accept-Language", "en-GB");
//or "en-GB,en;q=0.7" or similar
continue with your program flow

If the language parameter should depend on the one set in the browser, it would make sense to use your .Net approach. When the user requests the page with the applet on construction on the page insert the below described additional <parameter> tag. And modify the applet to send that value along. Hope I'm clear on this.



Assuming you really want to determine the browser version on the client side in an applet:

That isn't directly possible from java AFAIK as the applet shouldn't have to care in which browser it is running. But you could

  • with javascript first determine the browser version
  • with javascirpt then dynamically writing the applet tag
  • and passing the browser version in to the applet via a tag

Check Passing Parameters to Applets for a sample on how to do this.

This probably looks at the Accept-Language HTTP header, which you can get in Java by doing


Need Your Help

How can I inject from a field?

java spring dependency-injection

I use Spring and I can inject from a method.

How to know which field is invalid in knockout validation?

javascript knockout.js knockout-validation

I have a rather big knockout model and I want to validate all nested models in it: