webwork有这样一个标签,他可以去执行xwork用定义的action,然后把action返回的页面显示在调用这个标签的地方,从本质上说,action标签让你实现了前端控制器
Action:
package
ch9;
import javax.servlet.http.HttpServletRequest;
import com.opensymphony.webwork.interceptor.ServletRequestAware;
import com.opensymphony.xwork.ActionSupport;
public class TestActionTag extends ActionSupport implements ServletRequestAware ... {
HttpServletRequest request=null;
public void setServletRequest(HttpServletRequest request) ...{
this.request=request;
}
public String execute() throws Exception ...{
request.setAttribute("test", "test data");
for (int i = 0; i < 1000000; i++) ...{
System.out.println(i);
}
return SUCCESS;
}
}
import javax.servlet.http.HttpServletRequest;
import com.opensymphony.webwork.interceptor.ServletRequestAware;
import com.opensymphony.xwork.ActionSupport;
public class TestActionTag extends ActionSupport implements ServletRequestAware ... {
HttpServletRequest request=null;
public void setServletRequest(HttpServletRequest request) ...{
this.request=request;
}
public String execute() throws Exception ...{
request.setAttribute("test", "test data");
for (int i = 0; i < 1000000; i++) ...{
System.out.println(i);
}
return SUCCESS;
}
}
TestActionTagResult.jsp(action的跳转页面,显示我们的内容)
<%
...
@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030" %>
<! DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd" >
< html >
< head >
<% ... @ taglib uri="webwork" prefix="ww" %>
< meta http-equiv ="Content-Type" content ="text/html; charset=GB18030" >
< title > Insert title here </ title >
</ head >
< body >
< ww:property value ="#request.test" />
</ body >
</ html >
pageEncoding="GB18030" %>
<! DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd" >
< html >
< head >
<% ... @ taglib uri="webwork" prefix="ww" %>
< meta http-equiv ="Content-Type" content ="text/html; charset=GB18030" >
< title > Insert title here </ title >
</ head >
< body >
< ww:property value ="#request.test" />
</ body >
</ html >
TestActionTag.jsp(我们使用action标签的页面,并没有显示内容)
executeResult="true"才会去执行action返回的result
<%
...
@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030" %>
<! DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd" >
< html >
< head >
<% ... @ taglib uri="webwork" prefix="ww" %>
< meta http-equiv ="Content-Type" content ="text/html; charset=GB18030" >
< title > Insert title here </ title >
</ head >
< body >
< ww:action name ="testActionTag" executeResult ="true" />
</ body >
</ html >
pageEncoding="GB18030" %>
<! DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd" >
< html >
< head >
<% ... @ taglib uri="webwork" prefix="ww" %>
< meta http-equiv ="Content-Type" content ="text/html; charset=GB18030" >
< title > Insert title here </ title >
</ head >
< body >
< ww:action name ="testActionTag" executeResult ="true" />
</ body >
</ html >
xwork.xml
<
action
name
="testActionTag"
class
="ch9.TestActionTag"
>
< result name ="success" > /ch9/testActionTagResult.jsp </ result >
</ action >
< result name ="success" > /ch9/testActionTagResult.jsp </ result >
</ action >
运行结果TestActionTag.jsp,可以看到打印出了test data
后计:希望webwork能将此功能做成异步的,至于为什么,我想大家都清楚吧,这样,ajax就没什么市场了,呵呵