java开发web网页之servlet

使用servlet开发web网页其中比较重要的就是servlet文件和html文件之间以及servlet文件和js文件之间传递信息

servlet文件和html文件之间传递数据是html文件向servlet文件传递数据,方法是使用表单标签的action属性,还要指定method属性以表明是将数据传递给doGet()方法还是doPost()方法,将数据提交到servlet文件中,servlet文件再使用request.getParameter(key)方法获取表单中提交的值,key是表单中input标签的name属性。

servlet文件和js文件之间传递数据是使用JQuery的$post()方法和$get()方法,两个方法的API为:

jQuery.get(url, [data], [callback], [type])

url,[data],[callback],[type]

url:待载入页面的URL地址

data:待发送 Key/value 参数。

callback:载入成功时回调函数。

type:返回内容格式,xml, html, script, json, text, _default。

jQuery.post(url, [data], [callback], [type])

url,[data],[callback],[type]

url:发送请求地址。

data:待发送 Key/value 参数。

callback:发送成功时回调函数。

type:返回内容格式,xml, html, script, json, text, _default。

其中data参数将js文件数据传递到servlet中,callback函数中的data参数是从servlet传递数据到js中

猜你喜欢

转载自blog.csdn.net/imonkeyi/article/details/89283478