无法显示 WEB-INF 文件夹外的图像
Cannot show image outside WEB-INF folder
我有一个文件夹
结构文件夹:
我想在 index.jsp 上显示 img 文件夹中的图像。但是不会显示
到目前为止我试过了
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<jsp:include page="includes/header.jsp" />
<h2 class="page-header">Home</h2>
<base href="${pageContext.request.contextPath}/" />
<li><a href="${pageContext.request}/about">Home</a></li>
<a href="../../resources/img/1.png">
<img src="/resources/img/1.png" alt="logo">
<img src="WEB-INF/views/img/1.png" alt="studenst">
<img src="${pageContext.request.contextPath}/resources/img/1.png" />
<img src="#{request.contextPath}/resources/img/1.png" />
<h:graphicImage value="/resources/img/1.png" />
这是我的简单控制器。
public class HomeServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public HomeServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String path = request.getServletPath();
RequestDispatcher dispatcher = this.getServletContext().getRequestDispatcher("/WEB-INF/views/index.jsp");
dispatcher.forward(request, response);
}
为什么它不起作用?
如果我将 index.jsp 放在 web-inf 文件夹之外(在 Web 内容中),它会起作用。但是我想把 index.jsp 放在 web-inf.
里面
复制 1.png 的目录路径,然后粘贴到 src(您要提供图像的位置)
试试看
<img src="<c:url value="/resources/img/1.png" />" />
我有一个文件夹
结构文件夹:
我想在 index.jsp 上显示 img 文件夹中的图像。但是不会显示
到目前为止我试过了
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<jsp:include page="includes/header.jsp" />
<h2 class="page-header">Home</h2>
<base href="${pageContext.request.contextPath}/" />
<li><a href="${pageContext.request}/about">Home</a></li>
<a href="../../resources/img/1.png">
<img src="/resources/img/1.png" alt="logo">
<img src="WEB-INF/views/img/1.png" alt="studenst">
<img src="${pageContext.request.contextPath}/resources/img/1.png" />
<img src="#{request.contextPath}/resources/img/1.png" />
<h:graphicImage value="/resources/img/1.png" />
这是我的简单控制器。
public class HomeServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public HomeServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String path = request.getServletPath();
RequestDispatcher dispatcher = this.getServletContext().getRequestDispatcher("/WEB-INF/views/index.jsp");
dispatcher.forward(request, response);
}
为什么它不起作用?
如果我将 index.jsp 放在 web-inf 文件夹之外(在 Web 内容中),它会起作用。但是我想把 index.jsp 放在 web-inf.
里面复制 1.png 的目录路径,然后粘贴到 src(您要提供图像的位置)
试试看
<img src="<c:url value="/resources/img/1.png" />" />