在Servlet、Jsp代码中的跟路径(/),是http://192.168.0.1:8080/应用部署名
其实在开发中,就是WebContent目录,比如访问WebContent/user/a.jsp
在servlet中:request.getRequestDispatcher("/user/a.jsp");
绝对地址:http://192.168.0.1:8080/应用部署名/user/a.jsp
在JSP/HTML、CSS、Javascript、Action的跟路径(/),是http://192.168.0.1:8080
如果提交到a.jsp为:action="/应用部署名/user/a.jsp"
或action="<%=request.getContextPath()%>"/user/a.jsp"
如果提交到servlet为actiom="<%=request.getContextPath()%>/serveltName"
对于一个绝对路径:http://192.168.0.1:8080/应用部署名/user/a.jsp
request.getScheme():http
request.getServerName():127.0.0.1
request.getServerPort():8080
request.getContextPath():/应用部署名
通过相对路径得到绝对路径:
String path = request.getSession().getServletContext().getRealPath("/");
假设有一张图片WebContent/static/bg.png,如果war文件以Tomcat7demo的名字部署,有三个方式访问
1.直接访问 http://localhost:8080/Tomcat7demo/static/bg.png
2.在HTML链接中访问:<img src="/Tomcat7demo/static/bg.png" />
3.通过JAVA代码访问: ByteArrayInputStream bais = (ByteArrayInputStream)
getServletContext().getResourceAsStream("/static/bg.png");
Web 资源 路径
最新推荐文章于 2024-04-19 22:50:24 发布