我的webcontent/images文件夹中有两个图像文件the_logo.jpg和logo.png
我能够访问 .png 文件
<img alt="Powerpay1" src="./images/logo.png" width="250" height="50" />
但是无法访问.jpg文件
<img alt="Powerpay" src="./images/the_logo.jpg" width="250" height="50" />
我该如何解决这个问题? 如果需要任何其他信息,请随时询问。
注意:我使用的是 Apache tomcat。
最佳答案
使用
<img alt="Powerpay1" src="../images/logo.png" width="250" height="50" />
<img alt="Powerpay1" src="../images/the_logo.jpg" width="250" height="50" />
This code will take the cursor to the previous folder.
If you have two nested folder, use
../../
or three nested folders, use../../../
and so on to go to the root of the directory and browse respectly.
而不是
<img alt="Powerpay1" src="./images/logo.png" width="250" height="50" />
<img alt="Powerpay1" src="./images/the_logo.jpg" width="250" height="50" />
<小时/>
使用 scriptlet 来实现此目的的另一种最佳方法
例如:
<%
String base = request.getContextPath() + "/";
if (base == null || base.isEmpty()) {
base = "/";
}
%>
<img alt="Powerpay1" src="<%=base%>images/logo.png" width="250" height="50" />
关于java - jsp中无法访问jpg,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45276798/