views:

720

answers:

3

Hi,

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?

+1  A: 

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

request.getHeader("Accept-Language")
Ramon
A: 

[NEW ANSWER]

Ok I assume you do something like this in the applet

URL url = new URL("http://www.whateverwebservice.com/passmealongthedata");
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.


[REMOVED]


[OLD ANSWER]

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.

jitter
apology for the confusion!!!I have no knowledge whatsoever in Java at all.I am working on a legacy application and they HttpContext.Current.Request.UserLanguages[0] to determine the language to use.Is it possible in JavaApplet to do something similar to HttpContext.Current.Request.UserLanguages[0]?This javaapplet calls a webservice and I need to pass something like "en-GB" etc.....I have tried to detect that in the webservice itself (.net 1.1) but no joy as HttpContext.Current.Request.UserLanguages[0] is null all the time.I hope this clarifies a bitThanks for your time
Jo
Extended answer
jitter
A: 

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.

jarnbjo
sorry to ask but I get the following problem"HttpServletRequest cannot be resolved"I have added this at the top "import javax.servlet.http.*;"but still no luck ,cannot find what do I need to do?I was trying to do HttpServletRequest request = ServletActionContext.getRequest(); Locale userPreferredLocale = request.getLocale();any suggestions?
Jo