首先,我阅读了大量关于此的帖子,但是我无法设法使其工作。 我对jsp和web应用程序非常陌生。我想要做的是显示一个简单的图像。 我有这样的代码在servlet:在jsp中显示图像时出现错误
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
HttpSession sesion = request.getSession();
String filePath = getServletContext().getRealPath("image.jpg");
System.out.println(filePath);
sesion.setAttribute("image", filePath);
response.sendRedirect("products.jsp");
}
而这种代码在jsp:
<img alt="logo" src="${image}"/>
而在我的web应用程序的文件夹,这个是: folders image
最后,当我的网页加载,这是我得到: image does not display
我不知道是什么这里是错误吗?为什么它是如此复杂(也许不是,但我真的尝试了很多方法,而不是它们的工作)来显示一个简单的图像?
在此先感谢您的帮助!
PS:该文件夹是正确的,它打印没有问题中的println()
使用Firebug在Chrome中,用鼠标右键单击图片和检查什么的'src'属性的值。 – tima