在TOMCAT 7 Servlet中启用CORS进行后期处理 [英] enabling CORS in TOMCAT 7 servlets for post request
问题描述
我正在使用tomcat 7在Java(eclipse ee)中的我的Dynamic Web项目上运行我的servlet. 我已将以下段落添加到我的web.xml文件中(来自
I'm using tomcat 7 to run my servlets on my Dynamic web project in java (eclipse ee). I've added to my web.xml file the following paragraph (from https://tomcat.apache.org/tomcat-7.0-doc/config/filter.html#CORS_Filter/Introduction):
<filter>
<filter-name>CorsFilter</filter-name>
<filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>CorsFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>"
我正在尝试通过以下Angular JS代码使用chrome的发布请求:
I am trying to use the post request from chrome using the following angular js code:
app.controller("LoginControler", function($scope,$rootScope,$http) {
$scope.submit = function () {
$rootScope.ret = "clicked";
var data = {
CompanyName: $scope.CompanyName,
UserName: $scope.UserName,
Password: $scope.Password,
};
$http.post(URL, data).success(function(data, status) {
$rootScope.ret = data;
})
}
});
,我不断收到以下错误代码: "XMLHttpRequest无法加载 http://localhost:8080/Project-FrontEnd/ServletUsers .预检请求未通过访问控制检查:所请求的资源上不存在"Access-Control-Allow-Origin"标头.因此,不允许访问源"null".响应的HTTP状态码为403."
and I keep getting the following error code: "XMLHttpRequest cannot load http://localhost:8080/Project-FrontEnd/ServletUsers. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. The response had HTTP status code 403."
我尝试了所有可以找到但没有帮助的解决方案...请问任何人都可以解决我的问题吗?
I tried all solutions that I could find but no help...please can any body solve my problem?
推荐答案
您好,朋友们只将tomcat从版本7更新到版本8.5,解决了原始解决方案的问题.
hi friends only updating tomcat from version 7 to version 8.5 solved the problem with the original solution.
这篇关于在TOMCAT 7 Servlet中启用CORS进行后期处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!