struts2下使用jquery发ajax请求得不到响应



struts2下使用jquery发ajax请求得不到响应

用了一个Action接收ajax请求
XML/HTML code
?
1
2
3
<action name=”ajax” class=”pcenshao.struts2.jquery.JQueryAjaxAction”>
<result></result>
</action>
在Action里是这样子的
Java code
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
public class JQueryAjaxAction extends ActionSupport implements ServletResponseAware {
private String info;
private HttpServletResponse response;

@Override
public String execute() throws Exception {
System.out.println(“info:”+this.info);
if(“pcenshao”.equals(this.info)){
this.response.getWriter().println(“通过验证”);
}else{
this.response.getWriter().println(“验证失败”);
}
return Action.SUCCESS;
}
public void setServletResponse(HttpServletResponse arg0) {
this.response=arg0;
this.response.setContentType(“text/html;charset=gbk”);
}//只贴了一部分代码
filter是这样配置的
XML/HTML code
?
1
2
3
4
5
6
7
8
<filter>
<filter-name>struts</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
我确定javascript发送ajax请求,接收响应以及回调的代码没有问题(调试过),

而且Action是可以接到请求的,

就是发不出来响应,

浏览器没有反应,

怀疑是struts2 filter搞的鬼

请高手指教

还有一点要补充的,

如果把请求发到一个jsp文件里,然后在jsp文件里作出对客户端的响应,

是可以实现的

return null 试试。
对我有用[0] 丢个板砖[0] 引用 | 举报 | 管理
manutdsodagreen

manutdsodagreen
manutdsodagreen
本版等级:T2
#3 得分:0 回复于: 2010-03-14 09:56:53
strtuts的配置也要贴出来。
对我有用[0] 丢个板砖[0] 引用 | 举报 | 管理
pywepe

pywepe
pywepe
本版等级:T4
#4 得分:0 回复于: 2010-03-14 11:29:44
引用 3 楼 manutdsodagreen 的回复:
strtuts的配置也要贴出来。
XML/HTML code
?
1
2
3
4
5
6
7
8
9
10
11
12
<?xml version=”1.0″ encoding=”UTF-8″ ?>
<!DOCTYPE struts PUBLIC
“-//Apache Software Foundation//DTD Struts Configuration 2.0//EN”
“http://struts.apache.org/dtds/struts-2.0.dtd”>


<struts>
<package name=”jquery” extends=”struts-default” namespace=”/jquery”>
<action name=”ajax” class=”pcenshao.struts2.jquery.JQueryAjaxAction”>
<result></result>
</action>
</package>
</struts>
对我有用[0] 丢个板砖[0] 引用 | 举报 | 管理
sfli_g

sfli_g
sfli_g
本版等级:T3
#5 得分:0 回复于: 2010-03-14 11:48:04
你前台有反应也你ajax这里处理啊

ajax原理你还的去看看….
对我有用[0] 丢个板砖[0] 引用 | 举报 | 管理
kecy_niuniu

kecy_niuniu
真真真真真真
本版等级:T2
#6 得分:0 回复于: 2010-03-14 11:48:33
没有设置头文件?
Java code
?
1
this.response.setHeader(“Cache-Control”, “no-cache”);

输出流关闭没?
Java code
?
1
2
this.response.getWriter().flush();
this.response.getWriter().close();
对我有用[0] 丢个板砖[0] 引用 | 举报 | 管理
pywepe

pywepe
pywepe
本版等级:T4
#7 得分:0 回复于: 2010-03-14 16:51:36
引用 5 楼 sfli_g 的回复:
你前台有反应也你ajax这里处理啊

ajax原理你还的去看看….

浏览器端 我确定没有问题
你不相信呢 …
对我有用[0] 丢个板砖[0] 引用 | 举报 | 管理
pywepe

pywepe
pywepe
本版等级:T4
#8 得分:0 回复于: 2010-03-14 16:52:35
引用 6 楼 kecy_niuniu 的回复:
没有设置头文件?
Java code

this.response.setHeader(“Cache-Control”, “no-cache”);
输出流关闭没?
Java code

this.response.getWriter().flush();
this.response.getWriter().close();
你说的流没有关闭有点道理

我按上面说的 return null 就成功了
对我有用[0] 丢个板砖[0] 引用 | 举报 | 管理
pywepe

pywepe
pywepe
本版等级:T4
#9 得分:0 回复于: 2010-03-14 16:53:05
引用 2 楼 sunscok 的回复:
return null 试试。
高手 多谢