如何整合jquery和struts

汪云飞记录本 2008-03-12 09:46:44
我写了一段代码
JSP:
<html>
<head>

<script src="js/jquery-1.2.3.js" type="text/javascript"></script>
<script src="js/custom.js" type="text/javascript"></script>
</head>

<body>
<input type="text" id="in"/>
<input type="button" value='submit'onclick="output();"/>
<div id='out' ></div>
</body>
</html>
action:
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws IOException {
// TODO Auto-generated method stub
response.setContentType("text/xml; charset=gbk");
response.getWriter().print("<font color=blue>"+request.getParameter("in")+"<font>");
return null;
}
custom.js
function output(){

$.post("out.do?in="+$('#in').val(),null,function(msg){$('#out').html(msg);});
}
希望页面输入框的内容提交后直接谈过AJAX输出到页面上。现在debug能进入action,但是页面没有效果,使用$ajax也是这样
...全文
1710 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
enjerliang 2009-10-02
  • 打赏
  • 举报
回复
我也一直在寻找这方面的资料嘞
Run_LeoCat 2009-07-20
  • 打赏
  • 举报
回复
能告诉我你怎么解决的么?这种集成我照着你做的,回调函数执行不了,希望你把完整的代码发给我,我好学学你是怎么做的。谢谢,我的邮箱len126@163.com
wuloveleiforever 2009-01-07
  • 打赏
  • 举报
回复
朋友,谢谢你,解决了我一直不能用JQUERY与STRUTS结合的问题,非常感谢!请加我QQ:350513284
mrshelly 2008-03-13
  • 打赏
  • 举报
回复
确认你的 out.do?in=test

能被访问到.
手工组一个HTTP请求,看是否能正常返回.

或者
<form method="post" action="out.do?in=test">
<input type="submit" value="go" />
</form>

提交看一下,是否能返回你的预期结果.
汪云飞记录本 2008-03-13
  • 打赏
  • 举报
回复
我在action里debug能看request.getParameter("in")的值,是页面传过去的。
汪云飞记录本 2008-03-13
  • 打赏
  • 举报
回复
找到问题了是action里的response.setContentType("text/xml; charset=gbk");
应该是:
response.setContentType("text/html; charset=gbk");
汪云飞记录本 2008-03-13
  • 打赏
  • 举报
回复
有人帮忙看看吗?
汪云飞记录本 2008-03-12
  • 打赏
  • 举报
回复
没人来吗,求救呀!

52,797

社区成员

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

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