以下代码在localhost上运行应用程序时工作正常但在托管在实时服务器上时无效,因为ajax请求返回了错误代码
此网址不支持405 HTTP方法get。
我已经发出get请求并在doGet方法中处理此请求,然后当我尝试在实时服务器上运行此代码时出现了什么问题。
注意:仅发布所需的代码js代码
Client side code
$.ajax({
type:"GET",
url:"fetchdata1",
data:"cat="+cat,
success:function(data){
}
});
server side code
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String cat = request.getParameter("cat");
PrintWriter out= response.getWriter();
ArrayList<product> p = new ArrayList();
try {
con=ConnectionManager.getConnection();
ps = con.prepareStatement("Select product_id,images.product_name,image_name,company_name,price "
+ "from images,products where images.product_name = products.product_name AND "
+ "category_name = ?");
ps.setString(1,cat);
rs=ps.executeQuery();
while(rs.next())
{
product pr =new product();
pr.id = rs.getInt("product_id");
pr.name = rs.getString("product_name");
pr.company =rs.getString("company_name");
pr.image = rs.getString("image_name");
pr.price = rs.getDouble("price");
p.add(pr);
}
String json = new Gson().toJson(p);
response.setContentType("application/json");
out.println(json);
}