content: package lk.ijse.gdse68.student_management.Filter;
  
  import jakarta.servlet.FilterChain;
  import jakarta.servlet.ServletException;
  import jakarta.servlet.annotation.WebFilter;
  import jakarta.servlet.http.HttpFilter;
  import jakarta.servlet.http.HttpServletRequest;
  import jakarta.servlet.http.HttpServletResponse;
  
  import java.io.IOException;
  
  @WebFilter(urlPatterns = "/*")
  public class CORSFilter extends HttpFilter {
      @Override
      protected void doFilter(HttpServletRequest req, HttpServletResponse res, FilterChain chain) throws IOException, ServletException {
          System.out.println("CORS Filter");
          var origin = getServletContext().getInitParameter("origin");
  
          if (origin != null) {
              res.setHeader("Access-Control-Allow-Origin", origin);
              res.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS, PATCH");
              res.setHeader("Access-Control-Allow-Headers", "Content-Type");
              res.setHeader("Access-Control-Expose-Headers", "Content-Type");
          }
  
          chain.doFilter(req, res);
  
      }
  }
  