【问题标题】:Servlet not redirecting to jsp properlyServlet 未正确重定向到 jsp
【发布时间】:2014-10-09 20:58:04
【问题描述】:

我在$(document).ready 函数上有一个对servlet 的Ajax 调用。 完成所有操作后,servlet 尝试将请求和响应重定向到页面:

try {
    request.getServletContext().getRequestDispatcher("/index.jsp").forward(request,response);
    return;
} catch (ServletException| IOException e1) {
    e1.printStackTrace();
}

servlet 正在运行,因为我可以在日志中看到所有内容,但在我的 jsp 页面上,所有属性都是空的。

在 servlet 上:

request.setAttribute("test", 1);

关于 index.jsp:

${test}

它什么也不打印。 有人可以帮忙吗?

【问题讨论】:

    标签: java jsp servlets


    【解决方案1】:

    在 JSP 文件中,JSTL 表达式 (${...}) 只能访问变量。您必须首先加载您的请求属性:

    <jsp:useBean id="test" scope="request" class="java.lang.String" />
    

    然后就可以成功使用${test}

    【讨论】:

    • 现在s not loading the jsp and it gives me this error: useBean类属性java.lang.Integer的值无效`
    • @AndreDuarte:我的错...我忘了&lt;jsp:useBean .../&gt; 中的类应该有一个默认构造函数:-( - 已编辑。
    猜你喜欢
    • 2014-12-30
    • 1970-01-01
    • 1970-01-01
    • 2018-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多