Web 资源 路径

来源:互联网 发布:windows logo 编辑:程序博客网 时间:2024/05/20 22:01
 在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.jsprequest.getScheme():httprequest.getServerName():127.0.0.1request.getServerPort():8080request.getContextPath():/应用部署名通过相对路径得到绝对路径:String path = request.getSession().getServletContext().getRealPath("/");假设有一张图片WebContent/static/bg.png,如果war文件以Tomcat7demo的名字部署,有三个方式访问1.直接访问 http://localhost:8080/Tomcat7demo/static/bg.png2.在HTML链接中访问:<img src="/Tomcat7demo/static/bg.png" />3.通过JAVA代码访问: ByteArrayInputStream bais = (ByteArrayInputStream)getServletContext().getResourceAsStream("/static/bg.png");
原创粉丝点击