Yes, a cname would work. The simple reason is that the browser/java will use the host directive, which is obtained from the hostame entered in the address bar, or specified in the code of the webpage when it pulls up additional objects.
The way cname works, is it responds to requests for host1.domain1.com and responds with another dns name, say host2.otherdomain.com, which is queried by the resolver. This is all done by the resolver, and is separate from what is going on with app/browser, so it's "transparent" (For lack of a better descriptive word right now).
if the webpage is at www.foo.com, but your app is from www.bar.com, you can ask them to create a cname for bar.foo.com or something, that points to www.bar.com. The only other thing you need to then do is create a vhost on your webserver that listens for foo.bar.com as well as www.bar.com - if you are using vhosts.