我正在使用axios(在客户网站上)和jetty(在中间件中)
在使用axios.get或axios.post时非常顺畅...直到我使用axios.delete为止,一切仍然很好
然后删除时出现此错误:
在axios的javascript中
import axios from '../http'
export async function GetAllBooking(){
return await axios.get('/admin/booking').then(respone => {
return respone;
}).catch(e=> {
console.log(e);
});
}
export async function
Delete(id){
return await axios.delete('/admin/booking',{
params:{
id: id
}
}).then(respone=>{
return respone;
}).catch(e=> {
console.log(e);
});
}
在axios的配置中
从“ axios”导入axios;
axios.defaults.withCredentials=true;
const instance = axios.create({
// .. where we make our configurations
baseURL: 'http://localhost:8000'
});
// Add a request interceptor
axios.interceptors.request.use(function (config) {
// Do something before request is sent
return config;
}, function (error) {
// Do something with request error
return Promise.reject(error);
});
// Add a response interceptor
axios.interceptors.response.use(function (response) {
// Any status code that lie within the range of 2xx cause this function to trigger
// Do something with response data
return response;
}, function (error) {
// Any status codes that falls outside the range of 2xx cause this function to trigger
// Do something with response error
return Promise.reject(error);
});
export default instance;
创建doDelete时我在码头上做什么
public class AdminBooking extends HttpServlet{
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{
System.out.println("GET BOOKING - ADMIN ");
try {
resp.addHeader("Access-Control-Allow-Origin", "http://localhost:8080");
resp.addHeader("Access-Control-Allow-Credentials","true");
resp.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE");
HttpSession session=req.getSession(false);
if(session != null ) {
TTransport transport; //1
transport = new TSocket("localhost", 9090); //2
transport.open(); //3
TProtocol protocol = new TBinaryProtocol(transport); //4
connectDBService.Client client = new connectDBService.Client(protocol); //5 Must have in client
List<booking> lstbooking = client.GetBooking();
resp.setContentType("application/json;charset=UTF-8");
ServletOutputStream out = resp.getOutputStream();
Gson gson = new GsonBuilder().create();
JsonArray arr = gson.toJsonTree(lstbooking).getAsJsonArray();
out.print(arr.toString());
transport.close();
}
} catch (TTransportException e) {
e.printStackTrace();
} catch (TException e) {
e.printStackTrace();
}
}
protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{
int id = Integer.parseInt(req.getParameter("id"));
System.out.println("Delete Booking");
try {
resp.addHeader("Access-Control-Allow-Origin", "http://localhost:8080");
resp.addHeader("Access-Control-Allow-Credentials","true");
resp.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE");
resp.setContentType("application/json;charset=UTF-8");
HttpSession session=req.getSession(false);
if(session != null ) {
TTransport transport; //1
transport = new TSocket("localhost",9090); //2
transport.open(); //3
TProtocol protocol = new TBinaryProtocol(transport); //4
connectDBService.Client client = new connectDBService.Client(protocol); //5 Must have in client
int result = client.DeleteBooking(id);
ServletOutputStream out = resp.getOutputStream();
Gson gson = new GsonBuilder().create();
Map<String, Integer> res= new HashMap<>();
res.put("result",result);
JsonObject arr = gson.toJsonTree(res).getAsJsonObject();
out.print(arr.toString());
transport.close();
}
} catch (TTransportException e) {
e.printStackTrace();
} catch (TException e) {
e.printStackTrace();
}
}
}
请告诉我我的代码有什么问题@@我很累
谢谢