首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

java web关于web.xml中welcome-file的配置

2012-01-07 
求助 java web关于web.xml中welcome-file的配置如何把非根目录的文件设置为welcome-file?工程根目录为web,

求助 java web关于web.xml中welcome-file的配置
如何把非根目录的文件设置为welcome-file?
工程根目录为web,有一个文件夹为granted,内含一个index.jsp
把granted/index.jsp设置为welcome-file会造成
访问http://localhost:8080/web和访问http://localhost:8080/web/granted/index.jsp不同,后者的CSS、图片等路径都不对。求指导

[解决办法]
css、图片等路径不对,那就应该在jsp里面采用绝对路径吧。
jsp页面头加上
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

然后在要引用的地方使用相对路径

热点排行