Java Code Examples for com.opensymphony.xwork2.ActionContext#put()

The following examples show how to use com.opensymphony.xwork2.ActionContext#put() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Form1Action.java    From Project with Apache License 2.0 6 votes vote down vote up
@Override
public String execute() throws Exception{
    // 使用 Struts 中 ActionContext 对象接收表单的参数
    ActionContext actionContext = ActionContext.getContext();
    // 接收参数
    HttpParameters paramsMap = actionContext.getParameters();
    for(String key : paramsMap.keySet()){
        String value = paramsMap.get(key).getValue();
    }

    // 向 request 中存入数据 : request.setAttribute(String name, Object value);
    actionContext.put("requestName","requestGJXAIOU");
    // 向 session 中存入数据: request.getSession().setAttribute(String name, Object value);
    actionContext.put("sessionName", "sessionGJXAIOU");
    // 向 application 中存入数据 this.getServletContext().setAttribute(String name, Object value);
    actionContext.getApplication().put("applicationName", "applicationGJXAIOU");


    return SUCCESS;
}
 
Example 2
Source File: UserLoginInterceptor.java    From hrms with Apache License 2.0 5 votes vote down vote up
@Override
public String intercept(ActionInvocation actionInvocation) throws Exception {
ActionContext actionContext = actionInvocation.getInvocationContext();
  Object user = actionContext.getSession().get("user");   
     if(user != null){   
          return actionInvocation.invoke();   
     } else{
   	  actionContext.put("loginMessage", "您尚未登陆,请先登陆");
         return Action.LOGIN;   
     }   

}
 
Example 3
Source File: PermissionInterceptor.java    From hrms with Apache License 2.0 4 votes vote down vote up
@Override
public String intercept(ActionInvocation actionInvocation) throws Exception {
	ActionContext actionContext = actionInvocation.getInvocationContext();
	HttpServletRequest request = (HttpServletRequest) actionContext.get(StrutsStatics.HTTP_REQUEST);
	String userId = actionContext.getSession().get("userId").toString();
	String contextPath = request.getContextPath();
	StringBuffer url = request.getRequestURL();
	int contextPathPost = url.lastIndexOf(contextPath);
	int contextPathLength = contextPath.length();
	String linkUrl = url.substring(contextPathPost + contextPathLength + 1);
	String actionId = "";
	int bottomLine = linkUrl.lastIndexOf("_");
	String action = linkUrl.substring(bottomLine+1);
	if(bottomLine < 0 || action.equals("my")) {
		actionId = "1";
	} else if(action.equals("add")) {
		actionId = "2";
	} else if (action.equals("update")) {
		actionId = "3";
	}else if (action.equals("delete")) {
		actionId = "4";
	} else if (action.equals("approverList") || action.equals("transactorList")) {
		actionId = "5";
	} else {
		actionId = "6";
	}
	if (bottomLine>0) {
		linkUrl = linkUrl.substring(0,bottomLine);
	}
	Module module = moduleService.getModuleByLinkUrl(linkUrl);
	if (userId != null && module!=null) {
		String moduleId = module.getModuleId().toString();
		if (userPermissionService.checkPermission(userId, moduleId,actionId)) {
			return actionInvocation.invoke();
		}
	}
	if (module==null) {
		return actionInvocation.invoke();
	}
	actionContext.put("permissionMessage", "你没有该权限,请先登陆");
	return Action.NONE;
}