public String updateUser() { User updateUser = userService.findUserById(this.id); ActionContext.getContext().getSession().put("updateUser", updateUser); ActionContext.getContext().getSession().put("userAction", -1); // userAction: -1 表示无效的用户信息 return SUCCESS; }
@Override public String execute() throws Exception { ActionContext ctx = ActionContext.getContext(); ServletContext sc = (ServletContext) ctx.get(ServletActionContext.SERVLET_CONTEXT); ApplicationContext appContext = WebApplicationContextUtils.getRequiredWebApplicationContext(sc); CourseManagerImpl cmi = (CourseManagerImpl) appContext.getBean("CourseManagerImpl"); StudentManagerImpl smi = (StudentManagerImpl) appContext.getBean("StuManagerImpl"); List cmiList = cmi.getCourses(); List smiList = smi.getStudents(); Map cmiMap = new HashMap(); Map smiMap = new HashMap(); for (int i = 0; i < cmiList.size(); i++) { Course course = (Course) cmiList.get(i); cmiMap.put(course.getCoursId(), course.getCoursName()); } for (int i = 0; i < smiList.size(); i++) { Student student = (Student) smiList.get(i); smiMap.put(student.getStuId(), student.getStuName()); } ActionContext actionContext = ActionContext.getContext(); Map session = actionContext.getSession(); session.put("cmiMap", cmiMap); session.put("smiMap", smiMap); return SUCCESS; }
public String logout() throws Exception { ActionContext.getContext().getSession().remove("username"); ActionContext.getContext().getSession().remove("fullName"); ActionContext.getContext().getSession().remove("role"); ActionContext.getContext().getSession().remove("user_id"); return ActionSupport.SUCCESS; }
public void testConditionalParseExpression() throws Exception { ValueStack oldStack = ActionContext.getContext().getValueStack(); try { OgnlValueStack stack = (OgnlValueStack) container.getInstance(ValueStackFactory.class).createValueStack(); stack.getContext().put(ActionContext.CONTAINER, container); stack.getContext().put("something", "somevalue"); ActionContext.getContext().setValueStack(stack); ValidatorSupport validator = new ValidatorSupport() { public void validate(Object object) throws ValidationException {} }; validator.setValueStack(ActionContext.getContext().getValueStack()); validator.setParse(true); String result1 = validator.conditionalParse("${#something}").toString(); validator.setParse(false); String result2 = validator.conditionalParse("${#something}").toString(); assertEquals(result1, "somevalue"); assertEquals(result2, "${#something}"); } finally { ActionContext.getContext().setValueStack(oldStack); } }
/** 分页 */ public String list() { // 1、定义每页显示多少行 int rowsPerPage = 5; // 定义每页显示几个页码 // int pageNumber = 5; // 转换当前页 int currentPage = this.pagingService.getCurrentPage(page); // 2、获取数据表中有多少行 int totalRowsNumber = this.pagingService.getTotalRowsNumber(); // 3、计算一共分多少页 int totalPage = this.pagingService.getPaging(totalRowsNumber, rowsPerPage); // 4、查询指定页面的数据并放到值栈 List<Employee> employeeList = this.pagingService.getSpecifiedPage(currentPage, rowsPerPage); // 对页码再进行分页 暂时不用 // Map<String, Integer> pagePaging = this.pagingService.getPagePaging(pageNumber, totalPage, // currentPage); Paging paging = new Paging(1, totalPage, currentPage, totalRowsNumber); // for (String key:pagePaging.keySet()) { // if (key.equals("startNumber")) { // paging.setHomePage(pagePaging.get(key)); // } // if (key.equals("endNumber")) { // paging.setEndPage(pagePaging.get(key)); // } // } ActionContext.getContext().put("paging", paging); ActionContext.getContext().put("employeeList", employeeList); return listAction; }
public void testModelOnSession() throws Exception { inter.setScope("session"); inter.setName("king"); User user = new User(); user.setName("King George"); Map session = new HashMap(); ActionContext.getContext().setSession(session); ActionContext.getContext().getSession().put("king", user); ScopedModelDriven action = new MyUserScopedModelDrivenAction(); MockActionInvocation mai = new MockActionInvocation(); MockActionProxy map = new MockActionProxy(); ActionConfig ac = new ActionConfig.Builder("", "", "").build(); map.setConfig(ac); mai.setAction(action); mai.setProxy(map); inter.intercept(mai); inter.destroy(); assertNotNull(action.getModel()); assertNotNull(action.getScopeKey()); assertEquals("king", action.getScopeKey()); Object model = ActionContext.getContext().getSession().get(action.getScopeKey()); assertNotNull(model); assertTrue("Model should be an User object", model instanceof User); assertEquals("King George", ((User) model).getName()); }
/** * 查询刷卡记录列表 * * @return */ public String getDriverRecordList() { HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(org.apache.struts2.StrutsStatics.HTTP_REQUEST); String searchTimeType = request.getParameter("searchTimeType"); String driverIds = request.getParameter("driverIds"); DriverStatInfo info = new DriverStatInfo(); String rpNum = request.getParameter("rp"); String pageIndex = request.getParameter("page"); String sortName = request.getParameter("sortname"); String sortOrder = request.getParameter("sortorder"); String state = request.getParameter("state"); String ln = request.getParameter("ln"); info.setSortname(sortName); info.setSortorder(sortOrder); info.setState(state); info.setVehicleLn(ln); try { if ("1".equals(searchTimeType)) { // 按时段查询 String start_time = request.getParameter("start_time"); String end_time = request.getParameter("end_time"); info.setBegTime(start_time + " 00:00:00"); info.setEndTime(end_time + " 23:59:59"); } else { String month = request.getParameter("month"); String first = month + "-01"; Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, Integer.parseInt(month.substring(0, 4))); cal.set(Calendar.MONTH, Integer.parseInt(month.substring(5, 7))); cal.set(Calendar.DAY_OF_MONTH, 1); cal.add(Calendar.DAY_OF_MONTH, -1); info.setBegTime(first + " 00:00:00"); info.setEndTime(month + "-" + cal.get(Calendar.DAY_OF_MONTH) + " 23:59:59"); } String searchIds = ""; if (driverIds.length() > 0) { String[] Ids = driverIds.split(","); // 字符串转字符数组 for (String id : Ids) { searchIds = searchIds + "'" + id + "',"; } info.setDriverId(searchIds.substring(0, searchIds.length() - 1)); } UserInfo user = (UserInfo) ActionContext.getContext().getSession().get(Constants.USER_SESSION_KEY); info.setEnterpriseId(user.getOrganizationID()); int totalCount = service.getCount("Drivershuaka.getDriverRecordCount", info); List<DriverStatInfo> list = service.getObjectsByPage( "Drivershuaka.getDriverRecordList", info, (Integer.parseInt(pageIndex) - 1) * Integer.parseInt(rpNum), Integer.parseInt(rpNum)); this.map = getDriverRecordPagination(list, totalCount, pageIndex, rpNum); } catch (BusinessException e) { log.info("司机刷卡记录查询异常", e); return ERROR; } return SUCCESS; }
/** * 更新关键字(排序和前台显示有关系数字越大越靠前) * * @return */ @Action( value = "UpdateKeywordT", results = {@Result(name = "json", type = "json")}) public String UpdateKeywordT() { if (Validate.StrNotNull(this.getSort())) { if (!Validate.isINTEGER_NEGATIVE(this.getSort())) { ActionContext.getContext().put("errormsg", "排序编号必须是正整数"); return "json"; } if (Validate.StrNotNull(this.getKeywordname())) { KeywordT kt = new KeywordT(); kt.setKeywordid(this.getKeywordid().trim()); kt.setKeywordname(this.getKeywordname().trim()); kt.setSort(Integer.parseInt(this.getSort().trim())); kt.setState(this.getState().trim()); kt.setType(this.getType().trim()); kt.setCreatetime(BaseTools.systemtime()); kt.setCreatorid(BaseTools.adminCreateId()); if (this.getKeywordTService().updateKeywordT(kt) > 0) { return "json"; } return "json"; } else { ActionContext.getContext().put("errormsg", "关键字名称必须填写"); return "json"; } } return "json"; }
public String authorizeUser() { User authorizeUse = userService.findUserById(id); List<UserRole> userRoles = userService.findUserRoleById(id); ActionContext.getContext().getSession().put("authorizeUser", authorizeUse); ActionContext.getContext().getSession().put("userRoles", userRoles); return SUCCESS; }
public TestAction() { application = ActionContext.getContext().getApplication(); request = (Map) ActionContext.getContext().get("request"); session = ActionContext.getContext().getSession(); System.out.println("application--------------------" + application); System.out.println("request----------------" + request); System.out.println("session----------------" + session); }
public String checkUser() { if (user.getUsername().equals("tongmi")) { ActionContext.getContext().getValueStack().push("该用户名已存在"); } else { ActionContext.getContext().getValueStack().push("该用户名可以使用"); } return SUCCESS; }
public void testNoTokenInSession() throws Exception { assertEquals(oldContext, ActionContext.getContext()); ActionProxy proxy = buildProxy(getActionName()); setToken(request); ActionContext.getContext().getSession().clear(); assertEquals(TokenInterceptor.INVALID_TOKEN_CODE, proxy.execute()); }
public String addUI() { posttypes = postTypeService.findAll(); ActionContext.getContext().put("posttypes", posttypes); // 标签云 List<Postlabel> postlabels = labelService.findAll(); ActionContext.getContext().put("postlabels", postlabels); return "addUI"; }
public boolean checkVerifycode(String verifycode) { String veriCode = (String) ActionContext.getContext().getSession().get("veriCode"); ActionContext.getContext().getSession().remove("veriCode"); if (veriCode == null || !veriCode.equals(verifycode)) { return false; } return true; }
@Override public String execute() { ActionContext.getContext().getSession().remove("id"); ActionContext.getContext().getSession().remove("name"); ActionContext.getContext().getSession().remove("admin"); return "success"; }
public String updateUI() { if (this.getModel().getId() != null) { Employee employee = this.getEmployeeService().getEmployee(this.getModel().getId()); ActionContext.getContext().put("employee", employee); Collection<Department> departmentList = this.departmentService.getAllDepartment(); ActionContext.getContext().put("departmentList", departmentList); } return updateUI; }
/** 修改页面 */ public String editUI() throws Exception { // 1、准备表单模板的数据 ApplicationTemplate at = applicationTemplateService.getById(model.getId()); ActionContext.getContext().getValueStack().push(at); // 2、准备所有的流程定义数据 List<ProcessDefinition> list = processDefinitionService.findAllLastVersion(); ActionContext.getContext().put("processDefinitionList", list); return "saveUI"; }
protected void setUp() throws Exception { super.setUp(); param = new HashMap<>(); interceptor = new MultiselectInterceptor(); ai = new MockActionInvocation(); ai.setInvocationContext(ActionContext.getContext()); ActionContext.getContext().setParameters(HttpParameters.create(param).build()); }
public String execute() throws Exception { logger.info("[login action start]-----username:[" + username + "]"); String sessRand = (String) ActionContext.getContext().getSession().get(WebConstants.SESS_RAND); if (rand == null || !rand.equals(sessRand)) { this.setReqMsg("验证码错误"); return ERROR; } User user = userBiz.login(username, password); if (user == null) user = userBiz.login(username, EncryptUtil.md5Encode(password)); if (user != null) { /* login successfully */ logger.info("loginName=[" + username + "] login successfully"); // add user name HttpSession session = ServletActionContext.getRequest().getSession(); session.setAttribute(WebConstants.SESS_USER_NAME, user.getLoginName()); session.setAttribute(WebConstants.SESS_USER_OBJ, user); if (user instanceof SuperAdmin) { session.setAttribute(WebConstants.SESS_USER_IS_EMPLOEE, null); session.setAttribute(WebConstants.SESS_PERMISSIONS, userBiz.getAllTopPermissions()); } else if (user instanceof Admin) { session.setAttribute(WebConstants.SESS_USER_IS_EMPLOEE, null); session.setAttribute(WebConstants.SESS_PERMISSIONS, userBiz.getAllTopAdminPermissions()); } else if (user instanceof Employee) { session.setAttribute(WebConstants.SESS_PERMISSIONS, userBiz.getAllTopEmployeePermissions()); session.setAttribute(WebConstants.SESS_USER_IS_EMPLOEE, "Y"); } // 登录提醒 List<LoginPrompt> list = userBiz.getAll(LoginPrompt.class); if (list != null && list.size() > 0 && list.get(0).getIsActive() != null && list.get(0).getIsActive()) { LoginPrompt p = list.get(0); long start = p.getStartDate() == null ? 0 : p.getStartDate().getTime(); long end = p.getEndDate() == null ? 0 : p.getEndDate().getTime(); long now = System.currentTimeMillis(); if (start > 0 && end == 0) { // 结束日期为空 if (now > start) { this.setReqMsg(p.getDescription()); } } else if (start > 0 && end > 0) { if (now > start && now < end + 24 * 60 * 60 * 1000) { this.setReqMsg(p.getDescription()); } } } } else { /* login failed */ logger.info("loginName=[" + username + "] login failed"); this.setReqMsg("登录失败,请检查用户名和密码"); return ERROR; } ActionContext.getContext().getSession().put("IS_HIS", null); return SUCCESS; }
public void logout() { ActionContext.getContext().getSession().clear(); ActionContext.getContext().getParameters().clear(); HttpServletResponse response = (HttpServletResponse) ActionContext.getContext().get(ServletActionContext.HTTP_RESPONSE); response.setHeader("Expires", "Thu, 19 Nov 1981 08:52:00 GMT"); response.setHeader( "Cache-Control", "no-store, no-cache, must-revalidate, post-check=0, pre-check=0"); response.setHeader("Pragma", "no-cache"); }
public void testValidToken() { String tokenName = "validTokenTest"; String token = TokenHelper.setToken(tokenName); assertEquals(token, session.get(tokenName)); ActionContext.getContext() .getParameters() .put(TokenHelper.TOKEN_NAME_FIELD, new String[] {tokenName}); ActionContext.getContext().getParameters().put(tokenName, new String[] {token}); assertTrue(TokenHelper.validToken()); }
@Override public String execute() throws Exception { Memberinfo member = (Memberinfo) ActionContext.getContext().getSession().get("member"); List<Memberinfo> friend = memberService.listFriend(member.getNickname()); // System.out.println(friend.size()+"ppppppppppppppppppppppppppppppppppp"); if (null != friend && friend.size() >= 0) { ActionContext.getContext().getValueStack().set("friend", friend); } return SUCCESS; }
public String delete() { if (userService.deleteUserById(this.id)) { // 当删除用户编号列表不为空,并且批量删除用户信息成功 msg = "删除成功!"; } else { msg = "删除失败!"; } ActionContext.getContext().getSession().put("msg", msg); ActionContext.getContext().getSession().put("userAction", 3); // userAction:3 表示删除用户信息 return SUCCESS; }
@Override public String execute() throws Exception { int scid = 0; if (ActionContext.getContext().getSession().get("id") != null) { scid = Integer.parseInt(ActionContext.getContext().getSession().toString()); } setScorelist(scoreService.loadScore()); setStu(studentService.loadStudentById(scid)); return SUCCESS; }
public String execute() throws Exception { try { String username = (String) ActionContext.getContext().getSession().get("LOGINUSERNAME"); String password = (String) ActionContext.getContext().getSession().get("LOGINPASSWORD"); if (username == null || password == null) { return LOGIN; } int page = 1; if (num != null) { page = num.intValue(); } int total = emailSendInfoService.getEmailSendInfoTotal(); pu = new PaginationUtil(total, page, SmgkConstants.PAGE_MAX_RESULT); pageList = emailSendInfoService.findEmailSendInfoByPage( pu.getStartRecord(), SmgkConstants.PAGE_MAX_RESULT); for (EmailSendInfo info : pageList) { if (pageList != null) { EmployeeInfo eInfo = employeeInfoService.getEmployeeInfo(info.getEmployeeID()); EmailAddressInfo eaInfo = emailAddressInfoService.getEmailAddressInfo(info.getAddressID()); AddressCatalogInfo acInfo = addressCatalogInfoService.getAddressCatalogInfo(info.getAcID()); if (eInfo != null) { eaList.add("" + eaInfo.getName()); } else { eaList.add(""); } if (eaInfo != null) { eList.add("" + eInfo.getName()); } else { eList.add(""); } if (acInfo != null) { acList.add("" + acInfo.getName()); } else { acList.add(""); } if (info.getStatus() != null) { statusList.add("" + StatusConstants.StatusDict.get(info.getStatus())); } else { statusList.add(""); } } else { this.addActionMessage("数据库中没有数据!"); } } } catch (Exception e) { logger.error("" + e.getMessage(), e.getCause()); } return SUCCESS; }
@Override public int getPageCountByProjectId(int currPage, int projectId, int flag) { ProjectSystem projectSystem = new ProjectSystem(); PagingService pagingService = new PagingServiceImpl(); if (currPage == 1 && flag == 1) { ActionContext.getContext().getSession().put("pId", projectId); } Integer integer = (Integer) ActionContext.getContext().getSession().get("pId"); int pId = integer.intValue(); return pagingService.getPageCountByProjectId(projectSystem, pId); }
@Override public List<ProjectSystem> pageListByBudgetId(int currPage, int budgetId, int flag) { ProjectSystem projectSystem = new ProjectSystem(); PagingService pagingService = new PagingServiceImpl(); if (currPage == 1 && flag == 1) { ActionContext.getContext().getSession().put("bId", budgetId); } Integer integer = (Integer) ActionContext.getContext().getSession().get("bId"); int bId = integer.intValue(); return pagingService.pageListByBudgetId(currPage, projectSystem, bId); }
public String myScore() throws Exception { int scid = 0; try { if (ActionContext.getContext().getSession() != null) { scid = Integer.parseInt(ActionContext.getContext().getSession().get("id").toString()); } setStu(studentService.loadStudentById(scid)); return "myscore"; } catch (Exception e) { return ERROR; } }
/** * 添加用户Action * * @return */ public String add() { if (!checkUser()) { if (userService.regist(this.user)) { // 添加用户信息 msg = "添加成功!"; } else { msg = "添加失败!"; } } ActionContext.getContext().getSession().put("msg", msg); ActionContext.getContext().getSession().put("userAction", 1); // userAction: 1 表示添加用户 return SUCCESS; }
public String agregarShape() { HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST); Map<String, Object> session = ActionContext.getContext().getSession(); try { if (shapefile != null) { boolean blnProcesoOk = false; String strFileTempName = "" + new Date().getTime(); List<File> listFile = abrirZip(shapefile, strFileTempName); if (listFile.size() > 0) { try { List<Map<String, String>> list = new Geotools().convertirShapeToImagen(listFile.get(0).getPath()); if (list != null) { if (list.size() > 1) { if (list.get(0).get("mensaje") != null && !CadenaUtil.getStr(list.get(0).get("mensaje")).equals("")) { addActionMessage(list.get(0).get("mensaje")); } this.listAreaShapeSeleccionar = list; blnProcesoOk = true; } else if (list.size() == 1) { if (list.get(0).get("mensaje") != null && !CadenaUtil.getStr(list.get(0).get("mensaje")).equals("")) { addActionMessage(list.get(0).get("mensaje")); } this.listAreaShapeSeleccionar = list; blnProcesoOk = true; } else { // TODO Error no hay datos addActionError("No se han encontrado datos para mostrar"); } } } catch (Exception ex) { this.listAreaShapeSeleccionar = null; addActionError(ex.getMessage()); } } else { addActionError("No se han encontrado archivos en el documento Zip"); } } else { addActionError("Debe adjuntar un documento en formato Zip conteniendo el shape"); } } catch (Exception ex) { ex.printStackTrace(); if (!CadenaUtil.getStr(ex.getMessage()).equals("")) { addActionError("Ocurrio un error:" + ex.getMessage()); } } return SUCCESS; }