JavaWeb项目相关小结

来源:互联网 发布:图像数据挖掘研究综述 编辑:程序博客网 时间:2024/06/05 08:58

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"/>


原创粉丝点击