2013-11-15 145 views
0

我已经上传图像到服务器机器文件夹像c:图像。 此<context-param> <description>Location to display uploaded file</description> <param-name>file-display</param-name> <param-value> C:/images/ </param-value> </context-param>图像显示在jsp从servlet

它上传得很清楚我写了“web.xml中”。 现在我需要在一个jsp上用<img src=""/>标签显示这些图像。

我发现在servlet的 使用

filepath = getServletContext().getInitParameter("file-display"); 

路径,以及附加的图像名称。 但是如何在jsp中用“<img src=""/>”标记表示。 有没有另一种方式来从服务器位置文件夹中jsp中显示图像。

回答

0

您应该能够使用预定义application变量访问ServletContext在JSP:

application.getInitParameter("file-display"); 

如果您正在使用的Servlet API 3.0(用于EL 2.2,它支持在表达式中调用方法),你可以这样做:

${application.getInitParameter("file-display")} 
+0

谢谢@micha,但我没有得到,你可以发送示例代码。 –