我正在请求servlet获取String值,因为我这样做。
function histryTraceFun(){
$.get('SendNodeHistoryTracing?node='+temp,function(response){
alert("in response "+response); // Here I am not getting response
});
}
在servlet中的doGet()方法,
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
String node=request.getParameter("node");
}
controll将进入servlet但不返回JSP,在回调函数警报中,变量response
的值不会出现。实际上我并不了解response.setContentType()
的工作原理。请允许任何人帮助我。谢谢。
答案 0 :(得分:1)
尝试将控件发送回您的页面:
RequestDispatcher dispatcher = request.getRequestDispatcher("/yourPage.html");
dispatcher.forward(request, response);
您还可以在响应中添加数据:
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
out.println("your_response");
RequestDispatcher dispatcher = request.getRequestDispatcher("/yourPage.html");
dispatcher.forward(request, response);
还有问题然后发布给我。