是否可以检查请求对象中是否存在属性?在某些错误情况下,必须将错误消息传递到客户端:
小服务程序代码:
request.setAttribute("error", "The following term was not found in the index: " + terms);
RequestDispatcher dispatcher = request.getRequestDispatcher("graph.jsp");
dispatcher.forward(request, response);
我像这样尝试过,但我根本没有收到警报窗口......
JSP 代码:
<script>
var test = "${error}";
if(test != null)
alert(test);
</script>