“是” 在哪里WEB-INF/duke.gif
?这张图片的路径是什么?
thufir@doge:~$
thufir@doge:~$ jar -tf NetBeansProjects/WebApplication/dist/WebApplication.war
META-INF/
META-INF/MANIFEST.MF
WEB-INF/
WEB-INF/classes/
WEB-INF/classes/beginnersbook/
WEB-INF/classes/beginnersbook/com/
WEB-INF/classes/net/
WEB-INF/classes/net/bounceme/
WEB-INF/classes/net/bounceme/dur/
WEB-INF/classes/net/bounceme/dur/filter/
WEB-INF/classes/net/bounceme/dur/servlets/
WEB-INF/images/
WEB-INF/classes/beginnersbook/com/Details.class
WEB-INF/classes/net/bounceme/dur/filter/Auth.class
WEB-INF/classes/net/bounceme/dur/filter/AuthenticateFilter.class
WEB-INF/classes/net/bounceme/dur/filter/SessionCheckFilter.class
WEB-INF/classes/net/bounceme/dur/servlets/Controller.class
WEB-INF/classes/net/bounceme/dur/servlets/MyToken.class
WEB-INF/classes/properties.properties
WEB-INF/duke.gif
WEB-INF/fail.jsp
WEB-INF/images/duke.gif
WEB-INF/login.jsp
WEB-INF/success.jsp
WEB-INF/web.xml
duke.gif
index.html
thufir@doge:~$
thufir@doge:~$ glassfish-4.1/glassfish/bin/asadmin deploy NetBeansProjects/WebApplication/dist/WebApplication.war
Application deployed with name WebApplication.
Command deploy executed successfully.
thufir@doge:~$
thufir@doge:~$ glassfish-4.1/glassfish/bin/asadmin list-applications
WebApplication <web>
Command list-applications executed successfully.
thufir@doge:~$
thufir@doge:~$
我想要引用这个文件,并将其加载到 JSP 中。
也可以看看:
https://stackoverflow.com/questions/28402583/load-image-in-filter-with-getservletcontext-getrealpath
答案1
使用 /WEB-INF/duke.gif
但是,您需要从 servlet 上下文中将其作为资源进行访问。
在您的 JSP 中:
<%
ServletContext ctx = request.getServletContext();
InputStream stream = ctx.getResourceAsStream("/WEB-INF/duke.gif");
%>
我希望这有帮助...