新建的JSP页面一般都有这
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head >
<base href="<%=basePath%>">
<title>DWR测试</title>
<script type="text/javascript" src="dwr/interface/checkName.js"></script>
<script type="text/javascript" src="dwr/interface/hello.js"></script>
<script type="text/javascript" src="dwr/engine.js" ></script>
<script type="text/javascript" src="js/util.js"></script>
</head>
<script language="javascript">
function Hello(){
var user=$("user").value;
checkName.findUserName(user,callback);
}
function callback(msg){
var infoDiv = document.getElementById("result");
if(msg){
infoDiv.innerHTML="正确"
}else{
DWRUtil.setValue('result','错误')
}
}
</script>
如果把<base href="<%=basePath%>">这个删除了
自己定义function 在里面
var name=$('user').value这样有问题
只能
var name=document.getElementById("user").value;
获取表单的值
然后调用DWR 传值到后台调用不进去
但是我看了一些其他人的代码项目里面都没有这个 <base href="<%=basePath%>">项目都是正常的运行
请问一下 你们一般都是这么解决这个问题的
------解决方案--------------------------------------------------------
是吗?没注意过。。。
------解决方案--------------------------------------------------------
我写的小例子是由base那个东西的。你的问题可能是其他原因吧。
- HTML code
<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%><%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%>"> <title>My JSP 'dwr.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- 下面的MyService.js中的MyService为dwr.xml中的javascript的值 --> <script type="text/javascript" src="/dwr/ajax/interface/MyService.js"></script> <script type="text/javascript" src="/dwr/ajax/engine.js"></script> <script type="text/javascript"> function doCal(){ var first = document.all.first.value; var second = document.all.second.value; var oper = document.all.oper.value; if(oper=="multi"){ MyService.multi(first,second,callback); } else if(oper=="div"){ MyService.div(first,second,callback); } else if(oper=="plus"){ MyService.plus(first,second,callback); } else if(oper=="sub"){ MyService.sub(first,second,callback); } } function callback(value){ var v = document.getElementById("value"); v.innerHTML = value; } </script> </head> <body> <input type="text" name="first" size="4"> <select name="oper"> <option value="multi">*</option> <option value="div">/</option> <option value="plus">+</option> <option value="sub">-</option> </select> <input type="text" name="second" size="4"> =<span id="value"></span> <br> <input type="button" value="计算" onclick="doCal()"/> </body></html>