jsp如何返回text给ajax请求?

tianbigao 2011-12-21 11:38:59
$(function (){
$.ajax({
type:'post',
url:'Tree.jsp',
dataType:'text',
success:function(msg)
{
alert(msg);
},
error:function()
{
alert('失败');
}
})
}


Tree.jsp页面就是从数据库读取三个字段:
int id;
int pid;
String text;
如何将读出来的值以text的方式返回给请求的页面?
...全文
294 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
chabale 2011-12-21
  • 打赏
  • 举报
回复
PrintWriter out = response.getWriter();
out.print("你要返回的内容");
huangxw000 2011-12-21
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 chabale 的回复:]
PrintWriter out = response.getWriter();
out.print("你要返回的内容");
[/Quote]
就是这样
zhouyusunquan 2011-12-21
  • 打赏
  • 举报
回复
在后台write一把,就行了撒
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 tianbigao 的回复:]
PrintWriter out = response.getWriter();
out.print("你要返回的内容");

用jsp内置对象的out不可以吗?
[/Quote]
jsp中的out对象是JspWriter类型的。
  • 打赏
  • 举报
回复
我也想知道这个问题
tianbigao 2011-12-21
  • 打赏
  • 举报
回复


PrintWriter out = response.getWriter();
out.print("你要返回的内容");

用jsp内置对象的out不可以吗?
zysnba 2011-12-21
  • 打赏
  • 举报
回复
后台
PrintWriter out = response.getWriter();
out.print("结果");

页面:
success:function(msg)

msg==结果

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧