JS文件引用不到(script 标签引用不到)

hughbeyond 2010-08-16 02:32:01
我是ssh初学者。不太懂用。请大家帮帮忙。

web.xml

<welcome-file-list>
<welcome-file>/WEB-INF/jsp/login/login.jsp</welcome-file>
</welcome-file-list>


<!-- Strut2 -->

<filter>
<filter-name>struts</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>


struts.properties


struts.action.extension=do,jsp
struts.serve.static=false


jsp 页面<%String path =request.getContextPath(); %>
<script type="text/javascript" src="<%=path%>struts/js/jquery-1.4.2.js"></script>

我的所有包的结构是

TemplateWAR
---struts
--js
--response.js
---Web-INF
--jsp
--login
--login.jsp



如下URL,则访问不到该JS文件
http://localhost:8080/TemplateWAR/struts/js/response.js

我在网上搜了很多,还是解决不了问题。
我之前把js放在web-inf下面,网上有人说放在那下面访问不到。
又有人说和web.xml中的struts2拦截器有关系,那个url-pattern。我也改了,还是不行。
请高人看看。

相关资源
http://topic.csdn.net/u/20090521/08/a99bdf3d-18a8-47e9-a817-6e974bb45a74.html
...全文
707 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
hughbeyond 2010-08-18
  • 打赏
  • 举报
回复
不过好像和项目没什么关系。

我用Myelispe建的也不能用js资源。
hughbeyond 2010-08-18
  • 打赏
  • 举报
回复
另外我建的项目是用 eclipse建的 Web Fragment 项目

hughbeyond 2010-08-18
  • 打赏
  • 举报
回复
回复10楼

http://localhost:8080/TemplateWAR/ 能进入 welcomefile的login.jsp
http://localhost:8080/ 您输入的域名或网址无法访问!

我的jsp


<%@ page contentType="text/html; charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%String path =request.getContextPath();
%>

<html>
<head>
<script type="text/javascript" src="${pageContext.request.contextPath}/struts/js/response.js"></script>
<script type="text/javascript" src="../../../../struts/js/request.js"></script>
<script type="text/javascript">

fuction showtips(str){

test();
abc();
}
/**
function showtips(str){

abc();
if(str.length==0){
document.getElementById("tips").innerHTML="";
return;

}
xmlHttp = request();
if(xmlHttp==null){

return;
}
alert($("username"));


var url="json/loginAjax.do";

var params ={username:document.getElementsByName("username").Value};
xmlHttp.open("POST",params,url,true);

xmlHttp.onreadystatechange=response;
xmlHttp.send(null);
}
function request() {
var xmlHttp;

try {
// Firefox, Opera 8.0+, Safari
xmlHttp = new XMLHttpRequest();
} catch (e) {

// Internet Explorer
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {

try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
alert("您的浏览器不支持AJAX!");
return false;
}
}
}

return xmlHttp;

}
function response(){

if (xmlHttp.readyState==4)
{
if (xmlHttp.status == 200) {
  alert(xmlHttp.responseText);
   } else {
  alert("您所请求的页面有异常。");
   }

alert(xmlHttp.responseText);

var data = eval(xmlHttp.responseText);


}

} **/
</script>

<style type="text/css">
.errorMessage{

color: red;
font-size: 9;
}
</style>
</head>
<body>
<form name="login" action="login.do" method="post" >
<table>
<tr>
<td>userName:</td><td><input name="username" type="text" onchange="showtips(this.value)"/></td>
<td id="tips"><s:fielderror><s:param>username</s:param></s:fielderror></td>
</tr>
<tr>
<td>password:</td><td><input name="password" type="password"/></td>
</tr>
<tr>
<td><input type="submit" name="submit" value="submit"/></td>
</tr>

</table>
</form>
</body>

</html>

tuo_bing 2010-08-18
  • 打赏
  • 举报
回复
貌试 TemplateWAR 不是工程的名称吧 ?

用相对路径试试


<script type="text/javascript" src="../struts/js/response.js"></script>
tuo_bing 2010-08-18
  • 打赏
  • 举报
回复
http://localhost:8080 可否?
http://localhost:8080/TemplateWAR/默认页 可否 ?
http://localhost:8080/TemplateWAR/struts/js/+重新写一个 js 文件,里面写简单内容看是否可以
hughbeyond 2010-08-17
  • 打赏
  • 举报
回复
没人知道?哭了。。。
hughbeyond 2010-08-16
  • 打赏
  • 举报
回复
另外 response.js

function abc(){

alert("");
}


javaemailkaifa 2010-08-16
  • 打赏
  • 举报
回复
帮顶,只要用request.getContextPath()就是获得项目根路径,在这个下面写就可以的。
hughbeyond 2010-08-16
  • 打赏
  • 举报
回复
回3楼,那个是我自己打上去打错了
wmdonald 2010-08-16
  • 打赏
  • 举报
回复
<script type="text/javascript" src="<%=path%>/struts/js/jquery-1.4.2.js"></script>
hughbeyond 2010-08-16
  • 打赏
  • 举报
回复
打出来是

/TemplateWAR
yangxiao_jiang 2010-08-16
  • 打赏
  • 举报
回复
把 request.getContextPath()打印出来,看看path的路径是否正确。

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧