[英]images display in jsp from servlet
I have uploaded images to server machine folder like c:images. 我已将图像上传到服务器计算机文件夹,例如c:images。 for this i have written "web.xml"
<context-param> <description>Location to display uploaded file</description> <param-name>file-display</param-name> <param-value> C:/images/ </param-value> </context-param>
为此,我编写了“ web.xml”。
<context-param> <description>Location to display uploaded file</description> <param-name>file-display</param-name> <param-value> C:/images/ </param-value> </context-param>
it is uploading perfectly well. 上传非常好。 Now i need to display those images in a jsp with
<img src=""/>
tag. 现在,我需要使用
<img src=""/>
标签在jsp中显示这些图像。
i am finding the path using 我正在寻找使用的路径
filepath = getServletContext().getInitParameter("file-display");
in servlet and also attached image name. 在servlet中,并附加了图像名称。 but how to represent in jsp with"
<img src=""/>
" tag. 但是如何用“
<img src=""/>
”标签在jsp中表示。 is there another way to diplay images in jsp from server location folder. 还有另一种方法可以从服务器位置文件夹中显示jsp中的图像。
You should be able to access the ServletContext
in jsp using the predefined application
variable: 您应该能够使用预定义的
application
变量在jsp中访问ServletContext
:
application.getInitParameter("file-display");
If you are using Servlet API 3.0 (for EL 2.2, which supports calling methods in expressions) you can do: 如果您使用的是Servlet API 3.0(用于EL 2.2,它支持表达式中的调用方法),则可以执行以下操作:
${application.getInitParameter("file-display")}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.