在我的应用程序中,我不使用ajax将数据发布到服务器中。我用@FormParam注释获取数据。当我插入数据或出现错误时,响应消息显示在空白页面中。我想要做的是我想在同一页面上显示此消息。但我不知道该怎么做。当我尝试使用ajax发送数据时,我总是会收到错误。这就是我没有使用它的原因。
这是我的表格:
<form action="Rest/hastaService/insertHasta" method="post"
name="myForm">
<input class="form-control" type="input" id="tcKimlik"
name="tcKimlik" size="11" maxlength="11" required
pattern="[0-9]{11}">
<input class="form-control" type="text" name="isim" id="isim">
<input class="form-control" type="text" name="soyisim" id="soyisim">
<input class="form-control" type="date" name="dogum" id="dogum">
<input class="form-control" type="text" name="meslek" id="meslek">
<input type="submit" class="btn btn-primary" value="Kaydet" />
</form>
服务器端:
@POST
@Path("/insertHasta")
@Consumes("application/x-www-form-urlencoded")
@Produces("application/json")
public Response createHastalar(@FormParam("tcKimlik") long tcKimlik, @FormParam("isim") String isim,
@FormParam("soyisim") String soyIsim, @FormParam("dogum") String dogumTarih,
@FormParam("meslek") String meslek) throws SQLException {
Hasta hasta = new Hasta();
List<Hasta> hastaList = new ArrayList<Hasta>();
hasta.setTcKimlik(tcKimlik);
hasta.setIsim(isim);
hasta.setSoyIsim(soyIsim);
hasta.setDogumTarih(dogumTarih);
hasta.setMeslek(meslek);
/*Check for hasta if they have appointment*/
if(access.randevuAra(tcKimlik) == true){
if(access.hastaAra(tcKimlik) == false){
hastaList.add(hasta);
if(access.saveHasta(hastaList) == true){
return Response.ok("Basariyla Kaydedildi!", MediaType.TEXT_PLAIN).build();
}else{
return Response.status(Status.BAD_REQUEST).entity("Hata!").build();
}
}else{
return Response.status(Status.BAD_REQUEST).entity("Hasta kaydı zaten var!").build();
}
}else{
return Response.status(Status.BAD_REQUEST).entity("Hasta Randevusu Bulunmamaktadir. Lutfen Randevu Aliniz!").build();
}
}