67,550
社区成员




public String login(){
userInfo = new UserInfo();
userInfo.setName(userName);
userInfo.setPassword(userPassword);
if(userService.checkPassword(userInfo)){
status = STATUS_SUCCESS;
}else {
status = STATUS_FAIL;
}
log.info(status+"");
if(status==STATUS_SUCCESS){
ActionContext.getContext().put(Constants.USER_SESSION, userName);
ActionContext.getContext().put(Constants.USER_PASS, userPassword);
Log.info(userName+" log in success!");
return SUCCESS;
}else {
return ERROR;
}
}
public class LoginInterceptor extends AbstractInterceptor {
private static Logger log = LoggerFactory.getLogger(LoginInterceptor.class);
@Override
public String intercept(ActionInvocation invocation) throws Exception {
ActionContext ctx = invocation.getInvocationContext();
Map session = ctx.getSession();
String user = (String) session.get(Constants.USER_SESSION);
log.info(user);
if (!StringUtils.isEmpty(user)) {
log.info(user+" has log in!");
return invocation.invoke();
}else {
log.info("未登录!");
}
ctx.put("tip", "你还没有登录");
return Action.LOGIN;
}
<package name="all" extends="json-default">
<interceptors>
<interceptor name="authority"
class="chris.action.LoginInterceptor"/>
<interceptor-stack name="mydefault">
<interceptor-ref name="defaultStack" />
<interceptor-ref name="authority" />
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="mydefault" />
<global-results>
<result name="login">/admin/login.ftl</result>
</global-results>
</package>
<package name="admin" namespace="/admin" extends="all">
<action name="addUser" class="chris.action.AdminAction" method="addUser">
<result name="success" type="json">
<param name="includeProperties">status</param>
</result>
</action>
<action name="login" class="chris.action.AdminAction" method="login">
<result name="success" type="freemarker">/admin/welcome.ftl</result>
<result name="error" type="freemarker">/admin/login.ftl</result>
<interceptor-ref name="defaultStack"></interceptor-ref>
</action>
<action name="welcome" class="chris.action.AdminAction" method="welcome">
<result name="success" type="freemarker">/admin/welcome.ftl</result>
</action>
</package>