Javascript 如何在 JSP 中包含 JS/CSS 文件(TOMCAT PROJECT)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14979939/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to Include a JS/CSS File in JSP (TOMCAT PROJECT)
提问by AHméd Net
i have an external javascript and css file and i want to incude it into my JSP file so im trying to test this code but is not working :
我有一个外部 javascript 和 css 文件,我想将它包含到我的 JSP 文件中,所以我尝试测试此代码但不起作用:
i don't want to use "include file='file.css'"
我不想使用“include file='file.css'”
<html>
<head>
<link href="css/bootstrap.min.css" rel="stylesheet"/>
<script src="js/jquery-latest.js"></script>
<script src="js/bootstrap.min.js"></script>
</head>
<body>
<form class="form-horizontal well">
login : <input type="text">
<br/>
passw : <input type="password">
</form>
</body>
</html>
回答by rootkit
Use
用
<link href="${pageContext.request.contextPath}/css/bootstrap.min.css" rel="stylesheet"/>
See http://docs.oracle.com/javaee/5/api/javax/servlet/http/HttpServletRequest.html#getContextPath%28%29
见http://docs.oracle.com/javaee/5/api/javax/servlet/http/HttpServletRequest.html#getContextPath%28%29

