I am trying to get string from java method using AJAX request($http GET) and then to show it in my html using AngularJS, but I can't access my java function to retrieve information from it. It gives me 404 not found error every time. If someone can give me some example of how to do it or change my code to work it would be really helpful.
My html:
<pre><!DOCTYPE html>
<html>
<head>
<title>Proba</title>
<script src="js/angular.js"></script>
<script src="js/angular-route.js"></script>
<script type="text/javascript" src="js/Proba.js"></script>
</head>
<body ng-app="app" ng-controller="kontroler">
<h1>Probavam po stoti put ovo sranje!!!</h1>
<h2>{{hello}}</h2>
<h2>{{kakobilo}}</h2>
</body>
</html>
My Angluar:
var app = angular.module("app",[]);
app.controller('kontroler',['$scope','$http',function($scope,$http){
$scope.hello = "Hello World!";
$scope.helloFunction = function(){
$http({
url: 'rest/servisi/ime',
method: 'GET'
}).then(function(resp){
$scope.bilokako = resp.data;
},function(resp){
});
};
$scope.helloFunction();
}]);
My java function:
package Servisi;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
@Path("/servisi")
public class Name {
@GET
@Path("/ime")
@Produces(MediaType.TEXT_PLAIN)
public String Naziv() {
return "Hello World from Function !!!";
}
}
My XML:
<pre><?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>Proba</display-name>
<welcome-file-list>
<welcome-file>Proba.html</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>services,org.codehaus.jackson.jaxrs</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<!--
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
What I have tried:
I give you my example in which I tried to access my information from java method, but I can't retrieve it with REST in AJAX request.