How to make connection between JS and Java backend servlet in Electron


I have an application which has HTML+JS as frontend and a Java servlet as backend to perform some file operation.

As an eclipse project I had web.xml as a connector between JS and Java servlet and the project I was running on tomcat server.

But in electron frontend will not be on server. However i tried keeping servlet on seperate tomcat server and I am getting 403 (Forbidden) error.

I have even tried connecting with a servlet sitting on real server (not localhost) and I got succeeded.

But in my desktop application I need to access the local servlet (if it is on localhost is also fine) not the servlet on real server.