Announcement Announcement Module
Collapse
No announcement yet.
CORS jar doesn't take effect in Spring Tool Suite Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • CORS jar doesn't take effect in Spring Tool Suite

    Hello everybody,
    I'm struggling to resolve the problem of cross origin.As I'm using Maven, I add java-property-utils-1.9 and cors-filter-1.9.2 to the pom.xml. Then I configured my web.xml like this



    <filter>
    <filter-name>CORS</filter-name>
    <filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class>
    </filter>
    <filter-mapping>
    <filter-name>CORS</filter-name>
    <url-pattern>/</url-pattern>
    </filter-mapping>

    I found in other conversations that it is working perfectly with eclipse and tomcat.But now, I'm using Spring Tool
    Suite and I don't know what It is going wrong! I'm I missing some further configurations ? Please help me if you have any suggestions.

  • #2
    Hey!

    I think I don't understand the question. The project you are working on has these Maven dependencies and runs fine if you start the app from within Eclipse, but doesn't when starting from within STS?

    -Martin

    Comment


    • #3
      Hello Martin,
      no I didn't try within eclipse.But I saw that it works fine to the people who are using eclipse and tomcat.So it should work in STS , too.But it doesn't work for me.My jsp is

      <!DOCTYPE html>
      <html>
      <head>
      <meta charset="UTF-8">
      <title>Ajax - La fonction ajax()</title>
      </head>

      <body>
      <div id="r">Cliquez sur "Charger et traiter les données" pour lancer la lecture et le traitement</div>
      <button id="action">Charger et traiter les données</button>
      <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
      <script>


      $(function() {
      $('#action').click(function() {
      var s = document.cookie.split(';');
      var l=s[0].split('=')[1];
      var settings = {
      type: 'GET',
      url: 'http://pc-demo-bi:8090/jasperserver-pro/rest/resources/public/folder1',
      // data:{JSESSIONID:l},
      timeout: 3000,
      success: function(data) {
      alert(data);
      }

      };
      $.ajax(settings);
      });
      });
      </script>
      </body>
      </html>
      You see, I can't access the URL 'http://pc-demo-bi:8090/jasperserver-pro/rest/resources/public/folder1' from Ajax , because L have cross origin issue.
      I configured the pom.xml like this

      <filter>
      <filter-name>CORS</filter-name>
      <filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class>
      </filter>
      <filter-mapping>
      <filter-name>CORS</filter-name>
      <url-pattern>/</url-pattern>
      </filter-mapping>
      and I added the jars I add java-property-utils-1.9 and cors-filter-1.9.2 to the pom.xml.
      this is my controller

      package com.mycompany.myapp;

      import javax.servlet.Filter;

      import org.springframework.stereotype.Component;
      import org.springframework.web.bind.annotation.RequestMap ping;
      import org.springframework.web.bind.annotation.RequestMet hod;

      import javax.servlet.FilterChain;
      import javax.servlet.FilterConfig;
      import javax.servlet.ServletException;
      import javax.servlet.ServletRequest;
      import javax.servlet.ServletResponse;
      import javax.servlet.http.HttpServletResponse;

      import java.io.IOException;
      import java.text.DateFormat;
      import java.util.Date;
      import java.util.Locale;

      import org.slf4j.Logger;
      import org.slf4j.LoggerFactory;
      import org.springframework.stereotype.Controller;
      import org.springframework.ui.Model;
      import org.springframework.web.bind.annotation.RequestMap ping;
      import org.springframework.web.bind.annotation.RequestMet hod;
      import org.springframework.web.servlet.ModelAndView;

      /**
      * Handles requests for the application home page.
      */
      @Controller
      public class HomeController {


      @RequestMapping(value = "/", method = RequestMethod.GET)
      public ModelAndView rapportsPage() {
      ModelAndView model = new ModelAndView();

      model.setViewName("home");

      return model;
      }
      }
      I hope that it will help you figure out what is going wrong.Thanks in advance

      Comment


      • #4
        Hey!

        Can you maybe attach a full sample project? That would be great!

        Thanks!
        -Martin

        Comment


        • #5
          I can't attach the project here, I don't know why.I receive this error: Invalid File

          Comment


          • #6
            What about putting it up on DropBox and post the URL here?

            Comment

            Working...
            X