日期:2014-05-16  浏览次数:21053 次

struts 2.1的ajax局部刷新不起做用的问题

?

?

<%@ page contentType="text/html;charset=GBK" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="sx" uri="/struts-dojo-tags"%>
<html>
<head>
    <title>远程表单</title>
    <sx:head/>
</head>
<body>
<div id='show' style="background-color:#bbbbbb;width:360px;height:80px">原始静态文本</div>
使用表单请求的返回值来填充另一个Div。<br/>
<s:form id='theForm1'
        cssStyle="border: 1px solid black;"
        action='AjaxTest'
        method='post'
        theme="xhtml">
    <s:textfield name='data' label="请输入您喜欢的图书"/>
    <s:submit value="修改上面的静态文本" targets="show"/>
</s:form>
使用表单请求的返回值来填充本Form<br/>
<s:form id='theForm2'
        cssStyle="border: 1px solid black;"
        action='AjaxTest'
        method='post'
        theme="xhtml">
    <s:textfield name='data' label="请输入您喜欢的图书"/>
    <s:submit value="修改Form本身" targets="theForm2"/>
</s:form>
直接运行远程JavaScript(通过指定executeScripts="true")<br/>
<s:form id='theForm3'
        cssStyle="border: 1px solid black;"
        action='Test3'
        method='post'
        theme="xhtml">
    <s:textfield name='data' label="请输入您喜欢的图书"/>
    <s:submit value="执行远程JS" executeScripts="true" targets="show"/>
</s:form>
</body>
</html>

?这个是做的李刚的struts2权威指南11.4的例子,这里点击提交的时候没有进行局部刷新,却在新的页面显示信息,在网上查了一些说法,发现如果改成这样,就可以解决问题了、change the <s:submit> to <sx:submit>, and it's OK!?

<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="sx" uri="/struts-dojo-tags"%>
<html>
<head>
    <title>远程表单</title>
    <sx:head/>
</head>
<body>
<div id='show' style="background-color:#bbbbbb;width:360px;height:80px">原始静态文本</div>
使用表单请求的返回值来填充另一个Div。<br/>
<s:form id='theForm1'
        cssStyle="border: 1px solid black;"
        action='AjaxTest'
        method='post'
        theme="xhtml">
    <s:textfield name='data' label="请输入您喜欢的图书"/>
    <sx:submit value="修改上面的静态文本" targets="show"/>
</s:form>
使用表单请求的返回值来填充本Form<br/>
<s:form id='theForm2'
        cssStyle="border: 1px solid black;"
        action='AjaxTest'
        method='post'
        theme="xhtml">
    <s:textfield name='data' label="请输入您喜欢的图书"/>
    <sx:submit value="修改Form本身" targets="theForm2"/>
</s:form>
直接运行远程JavaScript(通过指定executeScripts="true")<br/>
<s:form id='theForm3'
        cssStyle="border: 1px solid black;"
        action='Test3'
        method='post'
        theme="xhtml">
    <s:textfield name='data' label="请输入您喜欢的图书"/>
    <sx:submit value="执行远程JS" executeScripts="true" targets="show"/>
</s:form>
</body>
</html>