怎样用document.location.href定位到本页

来源:百度知道 编辑:UC知道 时间:2024/09/26 00:35:01
我在jsp中定义了一段javascript,用于提交请求时向自己传递两个参数,在本页进行处理,而不转向其他页。可是如果document.location.href="admin/adminIndex.jsp?参数1=XX&参数2=XX"的话,点击一次可以,当点击第二次时,url就会出错,变成了admin/admin/adminIndex.jsp,多了一级目录;如果我去掉admin就更不对了,连第一次也进不去了,这是怎么回事?有什么办法取代本页连接?我现在只能写完整的http://……无奈了。

在jsp前面加上
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

然后

document.location.href="<%=path%>/admin/adminIndex.jsp?参数1=XX&参数2=XX"

String arg1 = request.getParameter("参数1")
把两个参数拼了传过去