(一).DivTag1.jsp界面
<?xml version="1.0" encoding="utf-8"?>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
<%@ taglib prefix="sjg" uri="/struts-jquery-grid-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>AnchorTag 的使用</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="styles/layout.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="/js/showcase.js"></script>
<sj:head
locale="zh_CN"
loadAtOnce="true"
compressed="false"
jquerytheme="showcase"
customBasepath="themes"
loadFromGoogle="false"
debug="true"
/>
<script type="text/javascript">
$.subscribe('beforeDiv', function(event,data) {
alert('Before request ');
});
$.subscribe('completeDiv', function(event,data) {
if(event.originalEvent.status == "success")
{
$('#resultnormal').append('<br/><br/><strong>Completed request '+event.originalEvent.request.statusText+' completed with '+event.originalEvent.status+ '.</strong><br/>Status: '+event.originalEvent.request.status);
}
});
$.subscribe('errorDiv', function(event,data) {
$('#resulterror').html('<br/><br/><strong>Error request '+event.originalEvent.request.statusText+' completed with '+event.originalEvent.status+ '.</strong><br/>Status: '+event.originalEvent.request.status);
});
</script>
</head>
<body>
<s:url
id="ajax"
value="echo">
<s:param
name="echo"
value="%{'We love jQuery'}" />
</s:url>
<sj:div
id="resultnormal"
href="%{ajax}"
indicator="indicator"
onBeforeTopics="beforeDiv"
onCompleteTopics="completeDiv"
onErrorTopics="errorDiv"
cssClass="result ui-widget-content ui-corner-all">
<img
id="indicator"
src="images/indicator.gif"
alt="Loading..."
style="display: none" />
</sj:div>
<br/><br/>
<strong>Div with invalid URL:</strong>
<sj:div
id="resulterror"
href="not_exist.html"
indicator="indicator"
onCompleteTopics="completeDiv"
onErrorTopics="errorDiv"
cssClass="result ui-widget-content ui-corner-all">
<img
id="indicator"
src="images/indicator.gif"
alt="Loading..."
style="display: none" />
</sj:div>
</body>
</html>
(二).Action的写法:
package com.anchorajax;
import com.opensymphony.xwork2.ActionSupport;
public class Echo extends ActionSupport
{
private String echo;
private boolean escape = true;
public boolean isEscape() {
return escape;
}
public void setEscape(boolean escape) {
this.escape = escape;
}
public String getEcho() {
return echo;
}
public void setEcho(String echo) {
this.echo = echo;
}
public String execute() throws Exception {
return SUCCESS;
}
}
(三)struts.xml配置:
<action name="echo" class="com.anchorajax.Echo"> <result name="success">/echo.jsp</result> </action>
(四)echo.jsp页面:
<%@ taglib prefix="s" uri="/struts-tags"%>
<p>Echo : <s:property value="echo" e
scape="%{escape}"/></p>
(五)not_exist.html页面:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>not_exist.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
</head>
<body>
不存在!!!!!!!!!!!! <br>
</body>
</html>
(六)结果页面: