I'm trying to persist (insert data) using AngularJS and WebService REST in Java, when I click Insert, the following error appears in the console:
>POST link 415 (Unsupported Media Type).
What could it be?
// WEB.XML
<?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"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID"
version="2.5">
<!-- COMO DEFAULT, O NOME DO MEU PROJETO, ESSE NOME IRÁ APARECER NA URL -->
<display-name>Cast_Frotas</display-name>
<!-- MAPEANDO O SERVLET-->
<servlet>
<servlet-name>Jersey RESTfull</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>br.com.Cast_frotas.service</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey RESTfull</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
// MY ANGULAR CONTROL
$scope.inserir = function (){
$http.post(linkservice + "insert", $scope.curso).then(function(data){
alert('Curso inserido com sucesso!');
});
}
// COURSE CLASS
public class Curso {
private int id;
private String nome;
private String descricao;
public Curso() {
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getDescricao() {
return descricao;
}
public void setDescricao(String descricao) {
this.descricao = descricao;
}
}
// CLASS CtrlCURSO
public class CtrlCurso {
public boolean insert(Curso c){
return CursoDB.getInstance().insert(c);
}
public List<Curso> getList(){
return CursoDB.getInstance().getListAll();
}
}
// MY SERVICE
@POST
@Path("/insert")
public void inserirCurso(Curso c){
new CtrlCurso().insert(c);
}