gpt4 book ai didi

java - 在 Tomcat 服务器上使用 JSTL 标签库的问题

转载 作者:行者123 更新时间:2023-11-28 23:37:41 25 4
gpt4 key购买 nike

这听起来像是一个奇怪的问题,但我无法在 Tomcat 服务器上运行的 J2EE 应用程序中使用 jSTL 标记库。同样的 Web 应用程序在 GlassFish 服务器上运行得非常好,但是当我创建另一个项目并复制使用 jSTL 标记的 signup.jsp 时,我遇到了错误。我的 PageController 代码是,

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
out.println("ai");
try {

request.getRequestDispatcher("pages/signup.jsp").forward(request, response);

} finally {
out.println("af");
out.close();
}
}

这里只打印“af”而不打印“ai”。现在,如果我从 signup.jsp 中删除 jSTL 代码,那么该代码就可以正常工作。现在我的问题是我是否必须添加任何其他文件才能使 jSTL 文件在 tomcat 服务器中工作?提前致谢。

最佳答案

RequestDispatcher#forward(..) 的 Javadoc州

forward should be called before the response has been committed to the client (before response body output has been flushed). If the response already has been committed, this method throws an IllegalStateException. Uncommitted output in the response buffer is automatically cleared before the forward.

因此有道理

out.println("ai");

未打印。但似乎与标签库没有任何关系。此外,该规范并未说明任何有关标记库参与 RequestDispatcher 的内容,因此它可能只是供应商特定的行为。

关于java - 在 Tomcat 服务器上使用 JSTL 标签库的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23158855/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com