0

1 / I created this myPage.jsp page in a eclipse project named erixx :

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE>
<html><head></head>
<body>
<% 
String aaa= request.getParameter("aaa");
String bbb= request.getParameter("bbb");
out.println("Message received ! : aaa : " + aaa + ", bbb : " + bbb);
%>
</body>
</html>

2 / this url in firefox shows that the jsp works fine :

http://localhost:8080/erixx/myPage.jsp?aaa=123&bbb=456

=> Message received ! : aaa : " + 123 + ", bbb : " + 456

3 / i try to access the same jsp page from another project made inito eclipse, the AngularJS code is executed, but does not return the values aaa and bbb : I used the example given here

https://docs.angularjs.org/api/ng/service/$http#get

<html>  <head> <title>Your Shopping Cart</title>
    <script src="js/angular.min.js"></script>
    <script>
        var app = angular.module('myApp', []);  
        app.controller("CartController", function($scope, $http) {

$http({
  method: 'GET',
  url: 'http://localhost:8080/erixx/myPage.jsp?aaa=123&bbb=456'
}).then(function successCallback(response) {
    $scope.myData = "response : " + response.data;
    $scope.statuscode = response.status;
  }, function errorCallback(response) {
    $scope.myData = "reponse : " + response.data;
    $scope.statuscode = "An error occured";
  });       
        });
    </script>
</head>
<body ng-app="myApp">
    <div ng-controller="CartController">
        {{ myData }}
        </br>
        {{ statuscode }}
    </div>
</body>
</html>

=> response : null An error occured

It should work because :

  • "2 /" shows that the jsp works fine,

  • the angular code comes from the angularJS web site,

Any idea ?

1 Answer 1

1

Most likely, that is a problem from cross domain requests. You need to configure your server if you want to host different domain requests. In that case, you can test it adding the code below (which will allow access to all domain):

<%
response.addHeader("Access-Control-Allow-Origin","*"); 
String aaa= request.getParameter("aaa");
...
%>

Then JSP will respond with the requested resource and an Access-Control-Allow-Origin header in the response. The browser will check the origin in the header and allow the request.

Also check : Cross-Site Request Forgery

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot, your solution works fine. I'm gonna to study how to manage cross domain requests.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.