jspservletsweb-inf

Cannot show image outside WEB-INF folder


I have a folder structure folder:
structure folder

I want to show images on index.jsp from img folder. But it won't show

So far I tried

<%@ 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" />

And this is my simple controller.

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);
    }

Why its not working?

If I place index.jsp outside web-inf folder (in web content), its working. But I want to place index.jsp inside web-inf.


Solution

  • Copy the directory path of the 1.png and then paste in the src (where u want to provide the image)