Herr K collects some JavaScript encryption methods here. There is no best, you would need to select one based on interoperability with Java, but forge probably provides a matching functionality to Java using RSA with an appropriate padding scheme. As I see it this would only protect against a passive "attacker" who cannot manipulate requests.
So you generate a public/private key pair with the method of your choice and embed the public key in your client code. Then you would encrypt using the public key on the client and decrypt with the private key on the server.
You will need to set the contentType to text/plain
.
To receive an encrypted response from the server this should be extended a little bit. Since an asymmetric cipher like RSA is needed, the client only has a public key and the server a private key, the server can only sign a message with RSA, but not encrypt it. So the client will need to generate an AES key and send it to the server and the server will use this key to respond securely. By securely, I mean that the message will be confidential, but maybe not authentic. So some type of MAC should be added.
To extend it further, on the first message the client generates the AES key and encrypts the actual message with this key and additionally encrypts the AES key with RSA (this is called hybrid encryption). The server responds with a message encrypted using AES. For the rest of the session only AES is used. RSA is only used at the beginning of the session to establish the session key. This is handmade SSL without using the SSL capabilities of the browser.