1
I am trying to make persistence (insert data) using Angularjs and Webservice REST in Java, when I click Insert in the console, the following error appears:
POST http://localhost:8080/Cast_fleets/Rest/course/Insert 415 (Unsupported Media Type).
What could 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 CONTROL IN ANGULAR
$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);
}
What library are you using to process JSON on your Java Webservice?
– Felipe Marinho
Felipe, I’m using Jsonobject
– Matheus Minguini