[英]Servlet not redirecting to jsp properly
我在$(document).ready
函数上对servlet进行了Ajax调用。 完成所有操作后,servlet尝试将请求和响应重定向到页面:
try {
request.getServletContext().getRequestDispatcher("/index.jsp").forward(request,response);
return;
} catch (ServletException| IOException e1) {
e1.printStackTrace();
}
servlet正在运行,因为我可以在日志中看到所有内容,但是在我的jsp页面上,所有属性均为null。
在servlet上:
request.setAttribute("test", 1);
在index.jsp上:
${test}
它什么也不打印。 有人可以帮忙吗?
在JSP文件中,JSTL表达式( ${...}
)只能访问变量 。 您必须首先使用以下命令加载您的请求属性:
<jsp:useBean id="test" scope="request" class="java.lang.String" />
然后,您可以成功使用${test}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.