在eclipse中对web程序进行开发,当把非webroot根目录下的文件设置为主页时,如果对css目录采用相对路径,将会无法应用,这时需要对文件的相对路径进行修改,如果是jsp文件,直接加头文件对目录进行设置:
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
在原来的css目录中加上<%=basePath%>
而如果是html,则复制过来变成jsp,记得把头文件改成<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>。否则会乱码。