structs2与ajax结合的经验
2015-11-03 09:45
253 查看
structs2与ajax结合,无论采用$.post还是$.ajax都捕获不到服务器产生的错误,这是structs2内部设计的不是很好,
但是$.ajax捕获错误在servlet能做到。因为
public void serviceAction(HttpServletRequest request, HttpServletResponse response, ServletContext context,
ActionMapping mapping) throws ServletException {
Map extraContext = createContextMap(request, response, mapping, context);
// If there was a previous value stack, then create a new copy and pass it in to be used by the new Action
ValueStack stack = (ValueStack) request.getAttribute(ServletActionContext.STRUTS_VALUESTACK_KEY);
boolean nullStack = stack == null;
if (nullStack) {
ActionContext ctx = ActionContext.getContext();
if (ctx != null) {
stack = ctx.getValueStack();
}
}
if (stack != null) {
extraContext.put(ActionContext.VALUE_STACK, valueStackFactory.createValueStack(stack));
}
String timerKey = "Handling request from Dispatcher";
try {
UtilTimerStack.push(timerKey);
String namespace = mapping.getNamespace();
String name = mapping.getName();
String method = mapping.getMethod();
Configuration config = configurationManager.getConfiguration();
ActionProxy proxy = config.getContainer()。getInstance(ActionProxyFactory.class)。createActionProxy(
namespace, name, method, extraContext, true, false);
request.setAttribute(ServletActionContext.STRUTS_VALUESTACK_KEY, proxy.getInvocation()。getStack());
// if the ActionMapping says to go straight to a result, do it!
if (mapping.getResult() != null) {
Result result = mapping.getResult();
result.execute(proxy.getInvocation());
} else {
proxy.execute();
但是$.ajax捕获错误在servlet能做到。因为
public void serviceAction(HttpServletRequest request, HttpServletResponse response, ServletContext context,
ActionMapping mapping) throws ServletException {
Map extraContext = createContextMap(request, response, mapping, context);
// If there was a previous value stack, then create a new copy and pass it in to be used by the new Action
ValueStack stack = (ValueStack) request.getAttribute(ServletActionContext.STRUTS_VALUESTACK_KEY);
boolean nullStack = stack == null;
if (nullStack) {
ActionContext ctx = ActionContext.getContext();
if (ctx != null) {
stack = ctx.getValueStack();
}
}
if (stack != null) {
extraContext.put(ActionContext.VALUE_STACK, valueStackFactory.createValueStack(stack));
}
String timerKey = "Handling request from Dispatcher";
try {
UtilTimerStack.push(timerKey);
String namespace = mapping.getNamespace();
String name = mapping.getName();
String method = mapping.getMethod();
Configuration config = configurationManager.getConfiguration();
ActionProxy proxy = config.getContainer()。getInstance(ActionProxyFactory.class)。createActionProxy(
namespace, name, method, extraContext, true, false);
request.setAttribute(ServletActionContext.STRUTS_VALUESTACK_KEY, proxy.getInvocation()。getStack());
// if the ActionMapping says to go straight to a result, do it!
if (mapping.getResult() != null) {
Result result = mapping.getResult();
result.execute(proxy.getInvocation());
} else {
proxy.execute();
相关文章推荐
- SQL2008 SQL Server 代理服务提供的凭据无效
- SpannableString属性详解
- asp.net出现“未将对象引用设置到对象的实例”
- 关于tableViewCell的一些事情
- uvaoj 11520 - Fill the Square
- 网狐“CTableFrameSink”: 不能实例化抽象类
- 实例:避免错误参数的方法
- windows下生成github ssh 公钥
- 获取当前的日期和时间,并显示
- 自定义圆形(或者有倒角)的button
- C#第五天
- sdk 下载国内地址
- 习题2-2 韩信点兵 解题报告
- JavaScript生成GUID的算法
- webrtc的锁
- 2015(2016届)校园招聘季——中兴 篇
- PM 周刊第 2 期 2015-10-26
- 【Unity游戏开发之十一】基于NGUI的表情图文混排解决方案
- 浅谈如何辨别程序员的水平高低
- C# API 大全(简版)