struts2基础知识

[b]struts.xml:[/b]








converter="converter.DateConvert">

/example/{1}.jsp
login

[b]Action:[/b]
package action;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.interceptor.ApplicationAware;
import org.apache.struts2.interceptor.ParameterAware;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class BasicAction extends ActionSupport implements ParameterAware,
ServletRequestAware, ServletResponseAware, SessionAware,
ApplicationAware {


@Override
public void setApplication(Map arg0) {

}

@Override
public void setSession(Map arg0) {
//ActionContext.getContext().getSession();

}

@Override
public void setServletResponse(HttpServletResponse arg0) {


}

@Override
public void setServletRequest(HttpServletRequest arg0) {
//ActionContext.getContext().get("request");
}

@Override
public void setParameters(Map arg0) {

}

}
[b]converter:[/b]
package converter;

import java.awt.List;
import java.lang.reflect.Member;
import java.util.Arrays;
import java.util.Map;

import ognl.DefaultTypeConverter;

public class DateConvert extends DefaultTypeConverter {

@SuppressWarnings("rawtypes")
@Override
public Object convertValue(Map context, Object value, Class toType) {
if (toType == List.class)
{
return Arrays.asList(value);
}
return super.convertValue(context, value, toType);
}

@SuppressWarnings("rawtypes")
@Override
public Object convertValue(Map context, Object target, Member member,
String propertyName, Object value, Class toType) {

return super.convertValue(context, target, member, propertyName, value, toType);
}

}
[b]interceptor:[/b]
package interceptor;

import java.util.Map;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

@SuppressWarnings("serial")
public class BasicInterceptor extends AbstractInterceptor {

@Override
public String intercept(ActionInvocation arg0) throws Exception {
Map session = arg0.getInvocationContext().getSession();
if (null != session) {
// TODO
return arg0.invoke();
}
else{
return Action.LOGIN;
}
}

}

你可能感兴趣的:(系统整合)