javascript中的JSP路径问题
[code=JScript]
// 检测用户输入
function checkUserAdd()
{
var form=document.forms[0];
var n=form.name.value;
var age=form.age.value;
var joinDate=form.joinDate.value;
if(n== " ") {
alert( "用户名为不能为空 ");
return false;
}else {
alert( "用户名为: "+n);
}
if(age== " ") {
alert( "年龄为不能为空 ");
return false;
}else {
alert( "年龄名为: "+age);
}
if(joinDate== " ") {
alert( "日期不能为空 ");
return false;
}else {
alert( "日期为: "+joinDate);
}
return true;
}
function userSubmitForward() {
self.location= '/index.jsp ';
}
[/code]
[code=HTML] <%@ page language= "java " contentType= "text/html; charset=GBK "
pageEncoding= "GBK "%>
<%@ taglib prefix= "s " uri= "/struts-tags "%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN " "http://www.w3.org/TR/html4/loose.dtd ">
<html>
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=GBK ">
<script type= "text/javascript " src= "js/checkUser.js "> </script>
<title> Insert title here </title>
</head>
<body>
<!-- 添加用户的Action -->
<s:form action= "actions/User_add " method= "post " onsubmit= "return checkUserAdd(); ">
<table width= "50% " align= "center ">
<tr align= "center ">
<td>
<s:textfield id= "name " label= "用户名 " name= "name "> </s:textfield>
</td>
</tr>
<tr align= "center ">
<td>
<s:textfield id= "age " label= "年龄 " name= "age "> </s:textfield>
</td>
</tr>
<tr align= "center ">
<s:textfield id= "joinDate " label= "日期 " name= "joinDate "> </s:textfield>
</tr>
<s:submit value= "提交 " onclick= "userSubmitForward() "> </s:submit>
<s:reset type= "重置 "> </s:reset>
</table>
</s:form>
</body>
</html> [/code]
在js 代码中,self.location= '/index.jsp ';
中的/是代表WEB项目中的根路径么?就是WebRoot下的路径??
这个代码是想提交后跳转到index.jsp,防止出现重复刷新提交。但不能成功。
请问大神们,问题出在哪里。
------解决方案--------------------self.location= '/项目路径/index.jsp ';
------解决方案--------------------/index.jsp
这个是直接目录了,属于域名目录下的,ROOT里面的
如上,/项目路径/index.jsp
------解决方案--------------------可以把工程路径封住好,例如:<%
String path = request.getContextPath();
String basePath