JSP doesn't open CSS, Images and JS

前端 未结 3 1815
隐瞒了意图╮
隐瞒了意图╮ 2020-12-20 08:35

I\'m trying to put CSS, JS and IMGs on my JSP, but doesn\'t work, it\'s strange because I use c:url and \"jstl/core\"

I\'m use JSP, jstl and servlet, no

相关标签:
3条回答
  • 2020-12-20 08:47

    The url pattern "/" has a special meaning to the web server. It's used for default servlet mapping which is capable of serving the static content. The static content is JS, CSS, images, html resources. Directing these files to your servlet is wrong, because it's not capable to serve the static content.

    Change the servlet mapping to something @WebServlet(urlPatterns="/incidente")

    and use url localhost:8080/PainelProduct/incidente to forward to jsp page.

    Check this question to learn more about servlets and servlet mapping Mapping a specific servlet to be the default servlet in Tomcat.

    0 讨论(0)
  • 2020-12-20 08:51

    I have encountered the same problem and have not resolved it for a long time. Then I realized that it was a problem from the path of the images.

    Wrong path is like that;

    src>main>resources>images

    The order of files(path) should definitely be as follows.

    src>main>webapp>resources>images

    and you should to call the function like that;

    <img src="<c:url value="/resources/img/logo.png"/>" alt=""/>
    
    0 讨论(0)
  • 2020-12-20 09:00

    You are not escaping the " when using inside the href value, use ' instead

    0 讨论(0)
提交回复
热议问题