向服务器发送数据有get和post两种.
首先,要将body中的html代码替换为
hello world!
请输入名称:
不输入数据,怎么提交数据呢.
get
我们只要将基础篇(二)中的:
function hellopressed()
{
dojo.io.bind({
url: 'response.txt',
handler: hellocallback
});
}
替换为:
function hellopressed()
{
dojo.io.bind({
url: 'helloworldresponseget.jsp',
handler: hellocallback,
content: {name: dojo.byid('name').value }
});
}
即可.其中的url不用说也明白了吧.是相对路径.也就是说在helloworld.html的当前目录
下应该有一个 helloworldresponseget.jsp 文件. handler还是一样,处理返回的数据,
如果有的话.
content即为要发送的数据. 其中名称为name,name的值为你所输入的值.
这样,我们可以在jsp中写入简单的代码来获得这个值,以下为jsp中的代码
/*
' helloworldresponseget.jsp
' --------
'
' 打印name的值.
'
*/
response.setcontenttype(text/plain);
%>
hello ,欢迎来到dojo世界!
post
这种方法即为在form表单提交提交数据.
相应的html代码为:
hello world!
请输入名称:
dojo代码为:
function hellopressed()
{
dojo.io.bind({
url: 'helloworldresponsepost.jsp',
handler: hellocallback,
formnode: dojo.byid('myform')
});
}
这里将content属性变为了formnode属性.
jsp的代码不变.到此,dojo的基础篇告一段落. 这些内容来自dojo的官方网站. 更详细的内容请参考官网.
http://dojo.jot.com/wikihome/tutorials/helloworld