我尝试通过调用通过ajax传递Table id的Rest服务来从数据库中删除记录。
连接点击删除按钮的功能:
[$("#deleteRecord").click(function(){
$.ajax({
type:"DELETE",
datatype:"text",
url:"http:/localhost:8080/bookProject/book/bookAccess/deleteBook?bookNo="+$("#bookNo").val(),//URL of local rest service bookNo is the Id of input
success:function(data)
{
alert("success");
},
error:function(e)
{
alert("Ajax error");
console.log(e);
}
});
});][1]
服务器端代码如下:
@DELETE
@Path("/deleteBook")
@Produces(MediaType.TEXT_PLAIN)
@Consumes(MediaType.APPLICATION_JSON)
public String deleteBook(@QueryParam("bookNo")String bookNumber)
{
String message="Deleted Succesfully";
// jdbc to delete from database
try
{
MysqlDataSource ds=new MysqlDataSource();
ds.setServerName("localhost");
ds.setPort(3306);
ds.setUser("Sachu");
ds.setPassword("Password01");
Connection conn=ds.getConnection();
Statement stmt=conn.createStatement();
stmt.execute("delete from customer.booktable where bookNo="+bookNumber);
conn.close();
}
catch(SQLException e)
{
message ="Error in deleting from the database";
}
return message;
}
// 但是当我单击删除按钮时,控制台显示404(资源未找到)Tomcat 6错误。 我能够进行PUT,POST和GET操作。此外,当从HTML文档(而不是通过localhost)访问时,DELETE不会抛出错误。但是当通过localhost(同源)访问时,Tomcat会抛出错误。有人可以让我知道错误的来源是什么。谢谢。 Error Image
答案 0 :(得分:0)
答案是从网址中删除部分网址:_≟_ : ∀ {α} {A : Set α} -> (x y : A) -> Maybe (x ≡ y)
。
在Rest项目中给出相对路径就足够了。
使用"http:/localhost:8080/bookProject
,
删除功能正常。