Struts2中 如何应用草根ajax?

今天在用struts2 与Ajax结合的时候不能把数据取回到页面来了。。请大家帮帮忙:

html代码:

<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>




registor form






Registor Here.


name:



pswd:








后台struts的代码:

主要是execute()方法的代码:
public String execute() {
ApplicationContext ctx = new ClassPathXmlApplicationContext(
"applicationContext.xml");
UsersService userService = (UsersService) ctx.getBean("UsersService");
result = userService.checkUserName(username);
HttpServletResponse response = (HttpServletResponse) ActionContext
.getContext().get(
org.apache.struts2.StrutsStatics.HTTP_RESPONSE);

PrintWriter pw;
try {
pw = response.getWriter();
pw.write("test");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}//获取out输出对象
return null;
}

其他配置文件都没有 action也有反映 但是在页面上不知道怎么把数据拿回来显示。

[该贴被admin于2009-02-25 08:29修改过]

没配置的话,返回null时默认是渲染当前页吧?
您可以尝试构造自己的result类型,但我推荐您使用google的一个开源工具,我们曾经用过,方便实用。
地址:http://code.google.com/p/jsonplugin/
嗯 了解过这个json插件。。。result是一个boolean型的数据类型。。构造自己的result类型是什么意思?
我的意思是struts.xml里的那个result类型,默认是dispatcher吧,用那个插件后就得声明type是json,package也要继承json-default。文档里有更详尽的说明,但我也没用过那么多。
/show.jsp