标签:request tsp result 拦截器 ted conf 点击 默认 图解
// // Source code recreated from a .class file by IntelliJ IDEA // (powered by Fernflower decompiler) // package com.opensymphony.xwork2.interceptor; import com.opensymphony.xwork2.ActionInvocation; import java.io.Serializable; public interface Interceptor extends Serializable { void destroy(); void init(); String intercept(ActionInvocation var1) throws Exception; }
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1"> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>首页</title> </head> <body> <a href="${pageContext.request.contextPath}/update">更新</a> <a href="${pageContext.request.contextPath}/save">保存</a> </body> </html>
package com.xuweiwei.domain; import java.io.Serializable; public class User implements Serializable { private String username; private String password; public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } }
package com.xuweiwei.action; import com.opensymphony.xwork2.Action; import com.opensymphony.xwork2.ActionSupport; import com.xuweiwei.domain.User; import org.apache.struts2.ServletActionContext; import javax.servlet.http.HttpSession; public class CustomerAction extends ActionSupport { //保存方法 public String save(){ System.out.println("保存"); return Action.SUCCESS; } //更新方法 public String update(){ System.out.println("更新"); return Action.SUCCESS; } //登录方法 public String login(){ HttpSession sessoin = ServletActionContext.getRequest().getSession(); sessoin.setAttribute("user",new User()); return Action.SUCCESS; } }
package com.xuweiwei.interceptor; import com.opensymphony.xwork2.Action; import com.opensymphony.xwork2.ActionInvocation; import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor; import com.xuweiwei.domain.User; import org.apache.struts2.ServletActionContext; import javax.servlet.http.HttpSession; public class LoginInterceptor extends MethodFilterInterceptor { @Override protected String doIntercept(ActionInvocation invocation) throws Exception { HttpSession session = ServletActionContext.getRequest().getSession(); User user = (User) session.getAttribute("user"); if(user != null){ return invocation.invoke(); }else{ return Action.LOGIN; } } }
<?xml version="1.0"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"> <struts> <package name="default" namespace="/" extends="struts-default"> <interceptors> <interceptor name="LoginInterceptor" class="com.xuweiwei.interceptor.LoginInterceptor"> <param name="excludeMethods">login</param> </interceptor> <interceptor-stack name="myDefaultStack"> <interceptor-ref name="LoginInterceptor"/> <interceptor-ref name="defaultStack"/> </interceptor-stack> </interceptors> <default-interceptor-ref name="myDefaultStack"/> <global-results> <result name="login" type="redirect">/login.jsp</result> </global-results> <action name="save" class="com.xuweiwei.action.CustomerAction" method="save"> <result name="success">/success.jsp</result> </action> <action name="update" class="com.xuweiwei.action.CustomerAction" method="update"> <result name="success">/success.jsp</result> </action> <action name="login" class="com.xuweiwei.action.CustomerAction" method="login"> <result name="success">/index.jsp</result> </action> </package> </struts>
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>成功</title> </head> <body> 成功 </body> </html>
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>登录</title> </head> <body> <a href="${pageContext.request.contextPath}/login">登录</a> </body> </html>
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ taglib prefix="s" uri="/struts-tags" %> <html> <head> <title>首页</title> </head> <body> <s:property value="‘abcdefg‘.endsWith(‘a‘)"></s:property> </body> </html>
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ taglib prefix="s" uri="/struts-tags" %> <html> <head> <title>首页</title> </head> <body> <s:property value="@java.lang.Integer@MAX_VALUE"></s:property> </body> </html>
<?xml version="1.0"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"> <struts> <constant name="struts.ognl.allowStaticMethodAccess" value="true"></constant> </struts>
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ taglib prefix="s" uri="/struts-tags" %> <html> <head> <title>首页</title> </head> <body> <s:property value="@java.util.UUID@randomUUID()"></s:property> </body> </html>
// // Source code recreated from a .class file by IntelliJ IDEA // (powered by Fernflower decompiler) // package com.opensymphony.xwork2; import com.opensymphony.xwork2.inject.Container; import com.opensymphony.xwork2.util.ValueStack; import java.io.Serializable; import java.util.HashMap; import java.util.Locale; import java.util.Map; public class ActionContext implements Serializable { static ThreadLocal<ActionContext> actionContext = new ThreadLocal(); public static final String ACTION_NAME = "com.opensymphony.xwork2.ActionContext.name"; public static final String VALUE_STACK = "com.opensymphony.xwork2.util.ValueStack.ValueStack"; public static final String SESSION = "com.opensymphony.xwork2.ActionContext.session"; public static final String APPLICATION = "com.opensymphony.xwork2.ActionContext.application"; public static final String PARAMETERS = "com.opensymphony.xwork2.ActionContext.parameters"; public static final String LOCALE = "com.opensymphony.xwork2.ActionContext.locale"; public static final String TYPE_CONVERTER = "com.opensymphony.xwork2.ActionContext.typeConverter"; public static final String ACTION_INVOCATION = "com.opensymphony.xwork2.ActionContext.actionInvocation"; public static final String CONVERSION_ERRORS = "com.opensymphony.xwork2.ActionContext.conversionErrors"; public static final String CONTAINER = "com.opensymphony.xwork2.ActionContext.container"; private Map<String, Object> context; public ActionContext(Map<String, Object> context) { this.context = context; } public void setActionInvocation(ActionInvocation actionInvocation) { this.put("com.opensymphony.xwork2.ActionContext.actionInvocation", actionInvocation); } public ActionInvocation getActionInvocation() { return (ActionInvocation)this.get("com.opensymphony.xwork2.ActionContext.actionInvocation"); } public void setApplication(Map<String, Object> application) { this.put("com.opensymphony.xwork2.ActionContext.application", application); } public Map<String, Object> getApplication() { return (Map)this.get("com.opensymphony.xwork2.ActionContext.application"); } public static void setContext(ActionContext context) { actionContext.set(context); } public static ActionContext getContext() { return (ActionContext)actionContext.get(); } public void setContextMap(Map<String, Object> contextMap) { getContext().context = contextMap; } public Map<String, Object> getContextMap() { return this.context; } public void setConversionErrors(Map<String, Object> conversionErrors) { this.put("com.opensymphony.xwork2.ActionContext.conversionErrors", conversionErrors); } public Map<String, Object> getConversionErrors() { Map<String, Object> errors = (Map)this.get("com.opensymphony.xwork2.ActionContext.conversionErrors"); if (errors == null) { errors = new HashMap(); this.setConversionErrors((Map)errors); } return (Map)errors; } public void setLocale(Locale locale) { this.put("com.opensymphony.xwork2.ActionContext.locale", locale); } public Locale getLocale() { Locale locale = (Locale)this.get("com.opensymphony.xwork2.ActionContext.locale"); if (locale == null) { locale = Locale.getDefault(); this.setLocale(locale); } return locale; } public void setName(String name) { this.put("com.opensymphony.xwork2.ActionContext.name", name); } public String getName() { return (String)this.get("com.opensymphony.xwork2.ActionContext.name"); } public void setParameters(Map<String, Object> parameters) { this.put("com.opensymphony.xwork2.ActionContext.parameters", parameters); } public Map<String, Object> getParameters() { return (Map)this.get("com.opensymphony.xwork2.ActionContext.parameters"); } public void setSession(Map<String, Object> session) { this.put("com.opensymphony.xwork2.ActionContext.session", session); } public Map<String, Object> getSession() { return (Map)this.get("com.opensymphony.xwork2.ActionContext.session"); } public void setValueStack(ValueStack stack) { this.put("com.opensymphony.xwork2.util.ValueStack.ValueStack", stack); } public ValueStack getValueStack() { return (ValueStack)this.get("com.opensymphony.xwork2.util.ValueStack.ValueStack"); } public void setContainer(Container cont) { this.put("com.opensymphony.xwork2.ActionContext.container", cont); } public Container getContainer() { return (Container)this.get("com.opensymphony.xwork2.ActionContext.container"); } public <T> T getInstance(Class<T> type) { Container cont = this.getContainer(); if (cont != null) { return cont.getInstance(type); } else { throw new XWorkException("Cannot find an initialized container for this request."); } } public Object get(String key) { return this.context.get(key); } public void put(String key, Object value) { this.context.put(key, value); } }
// // Source code recreated from a .class file by IntelliJ IDEA // (powered by Fernflower decompiler) // package com.opensymphony.xwork2.util; import java.util.Map; public interface ValueStack { String VALUE_STACK = "com.opensymphony.xwork2.util.ValueStack.ValueStack"; String REPORT_ERRORS_ON_NO_PROP = "com.opensymphony.xwork2.util.ValueStack.ReportErrorsOnNoProp"; Map<String, Object> getContext(); void setDefaultType(Class var1); void setExprOverrides(Map<Object, Object> var1); Map<Object, Object> getExprOverrides(); CompoundRoot getRoot(); void setValue(String var1, Object var2); void setParameter(String var1, Object var2); void setValue(String var1, Object var2, boolean var3); String findString(String var1); String findString(String var1, boolean var2); Object findValue(String var1); Object findValue(String var1, boolean var2); Object findValue(String var1, Class var2); Object findValue(String var1, Class var2, boolean var3); Object peek(); Object pop(); void push(Object var1); void set(String var1, Object var2); int size(); }
// // Source code recreated from a .class file by IntelliJ IDEA // (powered by Fernflower decompiler) // package com.opensymphony.xwork2.util; import java.util.ArrayList; import java.util.List; public class CompoundRoot extends ArrayList { public CompoundRoot() { } public CompoundRoot(List list) { super(list); } public CompoundRoot cutStack(int index) { return new CompoundRoot(this.subList(index, this.size())); } public Object peek() { return this.get(0); } public Object pop() { return this.remove(0); } public void push(Object o) { this.add(0, o); } }
static ThreadLocal<ActionContext> actionContext = new ThreadLocal();
public static final String ACTION_NAME = "com.opensymphony.xwork2.ActionContext.name"; public static final String VALUE_STACK = "com.opensymphony.xwork2.util.ValueStack.ValueStack"; public static final String SESSION = "com.opensymphony.xwork2.ActionContext.session"; public static final String APPLICATION = "com.opensymphony.xwork2.ActionContext.application"; public static final String PARAMETERS = "com.opensymphony.xwork2.ActionContext.parameters"; public static final String LOCALE = "com.opensymphony.xwork2.ActionContext.locale"; public static final String TYPE_CONVERTER = "com.opensymphony.xwork2.ActionContext.typeConverter"; public static final String ACTION_INVOCATION = "com.opensymphony.xwork2.ActionContext.actionInvocation"; public static final String CONVERSION_ERRORS = "com.opensymphony.xwork2.ActionContext.conversionErrors"; public static final String CONTAINER = "com.opensymphony.xwork2.ActionContext.container";
private Map<String, Object> context;
public ActionContext(Map<String, Object> context) { this.context = context; }
public void put(String key, Object value) { this.context.put(key, value); }
public void setActionInvocation(ActionInvocation actionInvocation) { this.put("com.opensymphony.xwork2.ActionContext.actionInvocation", actionInvocation); }
public ActionInvocation getActionInvocation() { return (ActionInvocation)this.get("com.opensymphony.xwork2.ActionContext.actionInvocation"); }
this.put("com.opensymphony.xwork2.ActionContext.application", application); } public Map<String, Object> getApplication() { return (Map)this.get("com.opensymphony.xwork2.ActionContext.application"); }
public void setConversionErrors(Map<String, Object> conversionErrors) { this.put("com.opensymphony.xwork2.ActionContext.conversionErrors", conversionErrors); } public Map<String, Object> getConversionErrors() { Map<String, Object> errors = (Map)this.get("com.opensymphony.xwork2.ActionContext.conversionErrors"); if (errors == null) { errors = new HashMap(); this.setConversionErrors((Map)errors); } return (Map)errors; }
public void setLocale(Locale locale) { this.put("com.opensymphony.xwork2.ActionContext.locale", locale); } public Locale getLocale() { Locale locale = (Locale)this.get("com.opensymphony.xwork2.ActionContext.locale"); if (locale == null) { locale = Locale.getDefault(); this.setLocale(locale); } return locale; }
public void setName(String name) { this.put("com.opensymphony.xwork2.ActionContext.name", name); } public String getName() { return (String)this.get("com.opensymphony.xwork2.ActionContext.name"); }
public void setParameters(Map<String, Object> parameters) { this.put("com.opensymphony.xwork2.ActionContext.parameters", parameters); } public Map<String, Object> getParameters() { return (Map)this.get("com.opensymphony.xwork2.ActionContext.parameters"); }
public void setSession(Map<String, Object> session) { this.put("com.opensymphony.xwork2.ActionContext.session", session); } public Map<String, Object> getSession() { return (Map)this.get("com.opensymphony.xwork2.ActionContext.session"); }
public void setValueStack(ValueStack stack) { this.put("com.opensymphony.xwork2.util.ValueStack.ValueStack", stack); } public ValueStack getValueStack() { return (ValueStack)this.get("com.opensymphony.xwork2.util.ValueStack.ValueStack"); }
public void setContainer(Container cont) { this.put("com.opensymphony.xwork2.ActionContext.container", cont); } public Container getContainer() { return (Container)this.get("com.opensymphony.xwork2.ActionContext.container"); } public <T> T getInstance(Class<T> type) { Container cont = this.getContainer(); if (cont != null) { return cont.getInstance(type); } else { throw new XWorkException("Cannot find an initialized container for this request."); } }
public Object get(String key) { return this.context.get(key); }
public static void setContext(ActionContext context) { actionContext.set(context); } public static ActionContext getContext() { return (ActionContext)actionContext.get(); }
public void setContextMap(Map<String, Object> contextMap) { getContext().context = contextMap; } public Map<String, Object> getContextMap() { return this.context; }
Map<String, Object> getContext();
ValueStack valueStack = ActionContext.getContext().getValueStack();
ValueStack valueStack = (ValueStack) ActionContext.getContext().get(ValueStack.VALUE_STACK);
ValueStack valueStack = (ValueStack) ServletActionContext.getRequest().getAttribute("struts.valueStack");
void set(String var1, Object var2);
void setValue(String ognlExp, Object var2);
Object findValue(String var1);
String findString(String var1);
标签:request tsp result 拦截器 ted conf 点击 默认 图解
原文地址:http://www.cnblogs.com/xuweiweiwoaini/p/7941862.html