0

So, the answer is probably super easy, but I just can't seem to figure it out.

I have set up a REST webservice, according to this tutorial: https://spring.io/guides/gs/rest-service/ and have set up the Requestmapping and everything using postman, and that end is working like I intended to.

I am setting up my site locally, but when I try to send a get request with jquery, I am receiving the following error: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.

So I have understood that the problem is that I am trying to run my html from file:// and that the solution is to run it from localhost on the tomcat server and found this answer in another topic: Deploying just HTML, CSS webpage to Tomcat

However, I cannot find such a webapps folder, and I am assuming it is because my tomcat server is deployed using maven and springboot. So how do I deploy my html/js on the tomcat server when it is deployed this way?

I am working on a mac and with IntelliJ.

I.Brok
  • 319
  • 1
  • 2
  • 16
  • you need to enable Cross origin in your api, search for that – Ali Akbarpour Jun 24 '17 at 12:30
  • I had used the cors chrome plugin, which worked fine, for when my request was still a plain XMLHttpRequest, but as soon as I started using jquery, it didn't work anymore. So, still had to put my html on localhost. – I.Brok Jun 24 '17 at 12:49
  • what was you your requested host that didnt worked? – Ali Akbarpour Jun 24 '17 at 12:55
  • take a look to this link https://stackoverflow.com/questions/10752055/cross-origin-requests-are-only-supported-for-http-error-when-loading-a-local – Ali Akbarpour Jun 24 '17 at 13:01

2 Answers2

0

In your spring boot application you can put your index.html file in src/main/resources/static directory and it will be served by the application.

Also you may try to configure CORS in spring boot, see this answer for links.

ledniov
  • 2,302
  • 3
  • 21
  • 27
  • Omg, I can't believe how easy that was. Thanks a bunch. – I.Brok Jun 24 '17 at 12:28
  • @I.Brok Glad the solution worked. Would you mind accepting this answer? It might help people experiencing a similar issue and will help getting your question noticed. For more information, take a look at our [FAQ](https://stackoverflow.com/help/accepted-answer). Thanks and welcome to SO! – ledniov Jul 09 '17 at 17:05
0

If you are deploying normal web applications like jee apps you do it by placing your war file in webapps folder. The web apps folder is inside your tomcat

But for for intellij-idea go through this, it should work:

Where is my app placed when deploying to Tomcat?

Vishal Roy
  • 120
  • 1
  • 10
  • Thank you. That topic was also very informative. However, putting my statics in src/main/resources/static like mentioned by ledniov also did the trick :) – I.Brok Jun 24 '17 at 12:52