JavaWeb项目相关小结

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zhanghe687/article/details/78284191

1. WebRoot文件夹与WebContent:
WebRoot是使用MyEclipse自动创建的;WebContent是使用Eclipse自动创建的,本质是一样的。
因为浏览器是无法访问Tomcat下的WEB-INF目录下的文件,在加之web.xml一般会定义过滤路径
(例如:
 
<servlet-mapping>
  <servlet-name>SpringMVC</servlet-name>
  <url-pattern>/</url-pattern>
    </servlet-mapping>


),所以对于企业发布的项目是安全。



2. login.jsp中使用绝对路径来引用js和css文件。
 方法:①将js和css文件放入WebRoot文件夹。如图:


 ②login.jsp中定义c标签

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<c:set value="${pageContext.request.contextPath}" var="path" scope="page"/>

 ③使用${path}

<link rel="stylesheet" href="${path}/static/css/login.css"/>


猜你喜欢

转载自blog.csdn.net/zhanghe687/article/details/78284191