/*更新修改ScoreInfo信息*/ public String ModifyScoreInfo() { ActionContext ctx = ActionContext.getContext(); try { if (true) { Student_QQ287307421DAO student_QQ287307421DAO = new Student_QQ287307421DAO(); Student_QQ287307421 studentNumber = student_QQ287307421DAO.GetStudent_QQ287307421ByStudentNumber( scoreInfo.getStudentNumber().getStudentNumber()); scoreInfo.setStudentNumber(studentNumber); } if (true) { CourseInfo_QQ254540457DAO courseInfo_QQ254540457DAO = new CourseInfo_QQ254540457DAO(); CourseInfo_QQ254540457 courseNumber = courseInfo_QQ254540457DAO.GetCourseInfo_QQ254540457ByCourseNumber( scoreInfo.getCourseNumber().getCourseNumber()); scoreInfo.setCourseNumber(courseNumber); } scoreInfoDAO.UpdateScoreInfo(scoreInfo); ctx.put("message", java.net.URLEncoder.encode("ScoreInfo信息更新成功!")); return "modify_success"; } catch (Exception e) { e.printStackTrace(); ctx.put("error", java.net.URLEncoder.encode("ScoreInfo信息更新失败!")); return "error"; } }
public String execute() { ActionContext ctx = ActionContext.getContext(); if (enid == 1) { ctx.put("enid", Integer.valueOf(enid)); ctx.put("exnameTag", "gass"); return "gase"; } if (enid == 2) { ctx.put("enid", Integer.valueOf(enid)); ctx.put("exnameTag", "salt"); return "salt"; } if (enid == 3) { ctx.put("enid", Integer.valueOf(enid)); ctx.put("exnameTag", "co2"); return "co2"; } if (enid == 4) { ctx.put("enid", Integer.valueOf(enid)); ctx.put("exnameTag", "ben"); return "ben"; } if (enid == 5) { ctx.put("enid", Integer.valueOf(enid)); ctx.put("exnameTag", "styrene"); return "styrene"; } else { return "input"; } }
public String ShowMyFriends() { ActionContext ctx = ActionContext.getContext(); Object o = ctx.getSession().get("userName"); Map map = ctx.getParameters(); Object o2 = map.get("pageIndex"); Integer pageIndex = 0; if (o2 != null) { pageIndex = Integer.parseInt(((String[]) o2)[0]); } if (o == null) return "Log"; ScholarUser user = accountService.GetScholarUserByName(o.toString()); List<ScholarUser> suList = new ArrayList<ScholarUser>(); suList.addAll(user.getFriends()); List<ScholarUser> tempList = new ArrayList<ScholarUser>(); int startIndex = pageIndex * this.userPageSize; for (int i = 0; i < this.userPageSize; i++) { if ((i + startIndex) >= suList.size()) break; tempList.add(suList.get(i + startIndex)); } ctx.put("friendList", tempList); int totalPage = user.getFriends().size() / this.userPageSize; if (user.getFriends().size() % this.userPageSize > 0) totalPage++; ctx.put("totalPage", totalPage); return "SUC"; }
/*添加ScoreInfo信息*/ @SuppressWarnings("deprecation") public String AddScoreInfo() { ActionContext ctx = ActionContext.getContext(); try { if (true) { Student_QQ287307421DAO student_QQ287307421DAO = new Student_QQ287307421DAO(); Student_QQ287307421 studentNumber = student_QQ287307421DAO.GetStudent_QQ287307421ByStudentNumber( scoreInfo.getStudentNumber().getStudentNumber()); scoreInfo.setStudentNumber(studentNumber); } if (true) { CourseInfo_QQ254540457DAO courseInfo_QQ254540457DAO = new CourseInfo_QQ254540457DAO(); CourseInfo_QQ254540457 courseNumber = courseInfo_QQ254540457DAO.GetCourseInfo_QQ254540457ByCourseNumber( scoreInfo.getCourseNumber().getCourseNumber()); scoreInfo.setCourseNumber(courseNumber); } scoreInfoDAO.AddScoreInfo(scoreInfo); ctx.put("message", java.net.URLEncoder.encode("ScoreInfo添加成功!")); return "add_success"; } catch (Exception e) { e.printStackTrace(); ctx.put("error", java.net.URLEncoder.encode("ScoreInfo添加失败!")); return "error"; } }
public void testIncludeParameterInResult() throws Exception { ResultConfig resultConfig = new ResultConfig.Builder("", "") .addParam("actionName", "someActionName") .addParam("namespace", "someNamespace") .addParam("encode", "true") .addParam("parse", "true") .addParam("location", "someLocation") .addParam("prependServletContext", "true") .addParam("method", "someMethod") .addParam("param1", "value 1") .addParam("param2", "value 2") .addParam("param3", "value 3") .addParam("anchor", "fragment") .build(); ActionContext context = ActionContext.getContext(); MockHttpServletRequest req = new MockHttpServletRequest(); MockHttpServletResponse res = new MockHttpServletResponse(); context.put(ServletActionContext.HTTP_REQUEST, req); context.put(ServletActionContext.HTTP_RESPONSE, res); Map<String, ResultConfig> results = new HashMap<String, ResultConfig>(); results.put("myResult", resultConfig); ActionConfig actionConfig = new ActionConfig.Builder("", "", "").addResultConfigs(results).build(); ServletActionRedirectResult result = new ServletActionRedirectResult(); result.setActionName("myAction"); result.setNamespace("/myNamespace"); result.setParse(false); result.setEncode(false); result.setPrependServletContext(false); result.setAnchor("fragment"); result.setUrlHelper(new DefaultUrlHelper()); IMocksControl control = createControl(); ActionProxy mockActionProxy = control.createMock(ActionProxy.class); ActionInvocation mockInvocation = control.createMock(ActionInvocation.class); expect(mockInvocation.getProxy()).andReturn(mockActionProxy); expect(mockInvocation.getResultCode()).andReturn("myResult"); expect(mockActionProxy.getConfig()).andReturn(actionConfig); expect(mockInvocation.getInvocationContext()).andReturn(context); control.replay(); result.setActionMapper(container.getInstance(ActionMapper.class)); result.execute(mockInvocation); assertEquals( "/myNamespace/myAction.action?param1=value+1¶m2=value+2¶m3=value+3#fragment", res.getRedirectedUrl()); control.verify(); }
/*删除ScoreInfo信息*/ public String DeleteScoreInfo() { ActionContext ctx = ActionContext.getContext(); try { scoreInfoDAO.DeleteScoreInfo(scoreId); ctx.put("message", java.net.URLEncoder.encode("ScoreInfo删除成功!")); return "delete_success"; } catch (Exception e) { e.printStackTrace(); ctx.put("error", java.net.URLEncoder.encode("ScoreInfo删除失败!")); return "error"; } }
/*前台查询ScoreInfo信息*/ public String FrontQueryScoreInfo() { if (currentPage == 0) currentPage = 1; List<ScoreInfo> scoreInfoList = scoreInfoDAO.QueryScoreInfoInfo(studentNumber, courseNumber, currentPage); /*计算总的页数和总的记录数*/ scoreInfoDAO.CalculateTotalPageAndRecordNumber(studentNumber, courseNumber); /*获取到总的页码数目*/ totalPage = scoreInfoDAO.getTotalPage(); /*当前查询条件下总记录数*/ recordNumber = scoreInfoDAO.getRecordNumber(); ActionContext ctx = ActionContext.getContext(); ctx.put("scoreInfoList", scoreInfoList); ctx.put("totalPage", totalPage); ctx.put("recordNumber", recordNumber); ctx.put("currentPage", currentPage); ctx.put("studentNumber", studentNumber); Student_QQ287307421DAO student_QQ287307421DAO = new Student_QQ287307421DAO(); List<Student_QQ287307421> student_QQ287307421List = student_QQ287307421DAO.QueryAllStudent_QQ287307421Info(); ctx.put("student_QQ287307421List", student_QQ287307421List); ctx.put("courseNumber", courseNumber); CourseInfo_QQ254540457DAO courseInfo_QQ254540457DAO = new CourseInfo_QQ254540457DAO(); List<CourseInfo_QQ254540457> courseInfo_QQ254540457List = courseInfo_QQ254540457DAO.QueryAllCourseInfo_QQ254540457Info(); ctx.put("courseInfo_QQ254540457List", courseInfo_QQ254540457List); return "front_query_view"; }
/*跳转到添加ScoreInfo视图*/ public String AddView() { ActionContext ctx = ActionContext.getContext(); /*查询所有的Student_QQ287307421信息*/ Student_QQ287307421DAO student_QQ287307421DAO = new Student_QQ287307421DAO(); List<Student_QQ287307421> student_QQ287307421List = student_QQ287307421DAO.QueryAllStudent_QQ287307421Info(); ctx.put("student_QQ287307421List", student_QQ287307421List); /*查询所有的CourseInfo_QQ254540457信息*/ CourseInfo_QQ254540457DAO courseInfo_QQ254540457DAO = new CourseInfo_QQ254540457DAO(); List<CourseInfo_QQ254540457> courseInfo_QQ254540457List = courseInfo_QQ254540457DAO.QueryAllCourseInfo_QQ254540457Info(); ctx.put("courseInfo_QQ254540457List", courseInfo_QQ254540457List); return "add_view"; }
protected void setUp() throws Exception { super.setUp(); stringWriter = new StringWriter(); writer = new PrintWriter(stringWriter); response = new StrutsMockHttpServletResponse(); response.setWriter(writer); servletContext = new StrutsMockServletContext(); stack = ActionContext.getContext().getValueStack(); context = new ActionContext(stack.getContext()); context.put(StrutsStatics.HTTP_RESPONSE, response); context.put(StrutsStatics.SERVLET_CONTEXT, servletContext); invocation = new MockActionInvocation(); invocation.setStack(stack); invocation.setInvocationContext(context); }
/*查询要修改的ScoreInfo信息*/ public String FrontShowScoreInfoQuery() { ActionContext ctx = ActionContext.getContext(); /*根据主键scoreId获取ScoreInfo对象*/ ScoreInfo scoreInfo = scoreInfoDAO.GetScoreInfoByScoreId(scoreId); Student_QQ287307421DAO student_QQ287307421DAO = new Student_QQ287307421DAO(); List<Student_QQ287307421> student_QQ287307421List = student_QQ287307421DAO.QueryAllStudent_QQ287307421Info(); ctx.put("student_QQ287307421List", student_QQ287307421List); CourseInfo_QQ254540457DAO courseInfo_QQ254540457DAO = new CourseInfo_QQ254540457DAO(); List<CourseInfo_QQ254540457> courseInfo_QQ254540457List = courseInfo_QQ254540457DAO.QueryAllCourseInfo_QQ254540457Info(); ctx.put("courseInfo_QQ254540457List", courseInfo_QQ254540457List); ctx.put("scoreInfo", scoreInfo); return "front_show_view"; }
@Override public String intercept(ActionInvocation invocation) throws Exception { String methodName = invocation.getProxy().getMethod(); Class clazz = invocation.getAction().getClass(); // 获取类对象 Method currentMethod = clazz.getMethod(methodName); // 获取拦截的方法 // 方法上添加了注解 if (currentMethod.isAnnotationPresent(Authority.class)) { // 取得当前请求的注解的action ActionContext context = invocation.getInvocationContext(); Map session = context.getSession(); // Constants.UserName=="UserName" String user = (String) session.get(Constants.UserName); // System.err.println("拦截器起作用"); if (user == null) // 未登陆,跳转到登录页 { // System.err.println("进入拦截器:未登陆"); context.put("tip", "你还没有登录"); return Action.LOGIN; } else { // 已登录,继续后续流程 // System.err.println("进入拦截器:已登录"); return invocation.invoke(); } } else { // System.err.println("进入拦截器:没有使用注解"); return invocation.invoke(); } }
public String intercept(ActionInvocation invocation) throws Exception { ActionContext ctx = invocation.getInvocationContext(); Map session = ctx.getSession(); Admin admin = (Admin) session.get("teacher"); if (admin != null && admin.getAid().intValue() <= 2) return invocation.invoke(); Object action = invocation.getAction(); if ((action instanceof BenQResultAction) || (action instanceof BenQualityAction) || (action instanceof BenResultTAction) || (action instanceof BenTResultAction) || (action instanceof CO2DataAction) || (action instanceof CommentAction) || (action instanceof DateDataAction) || (action instanceof DateTeamAction) || (action instanceof DeleteDataAction) || (action instanceof EditTeamAction) || (action instanceof GasDataAction) || (action instanceof LayExname) || (action instanceof LayExNameAction) || (action instanceof LayTeamAction) || (action instanceof SaltResultAction) || (action instanceof StyreneResultAction) || (action instanceof TeamHaveData) || (action instanceof TeamNoData) || (action instanceof UpdateTeamAction) || (action instanceof LayDataDispacher) || (action instanceof LayTeamDispacherAction) || (action instanceof DispacherURLData)) { return invocation.invoke(); } else { ctx.put("tip", "You Don't Have The Power to Perform this Action."); return "error"; } }
public String ShowAllPeople() { ActionContext ctx = ActionContext.getContext(); Map map = ctx.getParameters(); Object o2 = map.get("pageIndex"); Integer pageIndex = 0; if (o2 != null) { pageIndex = Integer.parseInt(((String[]) o2)[0]); } List<ScholarUser> suList = accountService.GetAllUser(pageIndex); ctx.put("friendList", suList); int totalUser = accountService.getTotalUserNum(); int totalPage = totalUser / this.userPageSize; if (totalUser % this.userPageSize > 0) totalPage++; ctx.put("totalPage", totalPage); return "SUC"; }
public String ShowPersonalInfo() { ActionContext ctx = ActionContext.getContext(); Map params = ctx.getParameters(); String[] list = (String[]) params.get("friendsId"); System.out.println("friendsId:" + list[0]); ScholarUser user = accountService.GetScholarUserById(Integer.parseInt(list[0])); ctx.put("User", user); return "SUC"; }
@Override protected void setUp() throws Exception { super.setUp(); this.request = new MockHttpServletRequest(); this.response = new MockHttpServletResponse(); ActionContext context = ActionContext.getContext(); ValueStack stack = context.getValueStack(); ActionContext.setContext(context); context.put(StrutsStatics.HTTP_REQUEST, this.request); context.put(StrutsStatics.HTTP_RESPONSE, this.response); MockServletContext servletContext = new MockServletContext(); context.put(StrutsStatics.SERVLET_CONTEXT, servletContext); this.invocation = new MockActionInvocationEx(); this.invocation.setInvocationContext(context); this.invocation.setStack(stack); }
@Override public String intercept(ActionInvocation ai) throws Exception { Map session = ai.getInvocationContext().getSession(); String userEmail = (String) session.get("activeUser"); if (userEmail != null && userEmail.length() > 0) { return ai.invoke(); } else { ActionContext ac = ai.getInvocationContext(); ac.put("popedom", "not login!"); return "notLogin"; } }
@SuppressWarnings("unchecked") @Override // µÇ¼À¹½ØÆ÷ public String intercept(ActionInvocation invocation) throws Exception { ActionContext context = invocation.getInvocationContext(); Map session = context.getSession(); User user = (User) session.get("user"); if (user != null) { return invocation.invoke(); } context.put("message", "Äú»¹Ã»ÓеǼ£¬ÇëµÇ¼ϵͳ¡£"); return Action.LOGIN; }
public String execute() throws Exception { ActionContext ac = ActionContext.getContext(); User user = (User) ac.getSession().get("user"); int id = user.getUserid(); PageBean pageBean = this.bookBiz.searchUnlineBookByUserid(id, currentPage, PAGESIZE); System.out.println(pageBean.getTotalPages()); // 将PageBean 放入Session中 // ac.getSession().put("pageBean", pageBean); ac.put("pageBean", pageBean); return "searchsuccess"; }
// 拦截Action处理的拦截方法 public String intercept(ActionInvocation invocation) throws Exception { // 取得请求相关的ActionContext实例 ActionContext ctx = invocation.getInvocationContext(); Map session = ctx.getSession(); // 取出名为user的Session属性 String user = (String) session.get("user"); // 如果没有登录,或者登录所用的用户名不是scott,都返回重新登录 if (user != null && user.equals("crazyit.org")) { return invocation.invoke(); } // 没有登录,将服务器提示设置成一个HttpServletRequest属性 ctx.put("tip", "您还没有登录,请输入crazyit.org,leegang登录系统"); // 直接返回login的逻辑视图 return Action.LOGIN; }
@Override // 拦截Action处理的拦截方法 public String intercept(ActionInvocation invocation) throws Exception { // TODO Auto-generated method stub // 取得请求相关的ActionContext实例 ActionContext ctx = invocation.getInvocationContext(); Map session = ctx.getSession(); // 取出名为loginName的session属性 String loginName = (String) session.get("loginName"); // 如果没有登陆,或者登陆用户不是系统管理员,则不能访问相应资源 if (loginName != null && (!"".equals(loginName))) { String str = AuthoritySupport.findAuthorityByLoginName(loginName); if (str.contains("系统管理员")) { return invocation.invoke(); } else { ctx.put("tip", "您没有相应的权限"); return Action.ERROR; } } else { ctx.put("tip", "您还没有登录,请登陆系统"); return Action.LOGIN; } }
public String execute() { ExnameDAO exDAO = new ExnameDAO(); Exname ex = exDAO.findById(Integer.valueOf(enid)); List teams = (new TeamsDAO()).findByEnid(ex.getEnid().intValue()); Set set = new HashSet(); String dates[] = date.split("-"); int beYear = Integer.parseInt(dates[0]); int beMonth = Integer.parseInt(dates[1]); int endYear = Integer.parseInt(dates[2]); int endMonth = Integer.parseInt(dates[3]); int begin = beYear * 12 + beMonth; int end = endYear * 12 + endMonth; for (Iterator iterator = teams.iterator(); iterator.hasNext(); ) { Teams t = (Teams) iterator.next(); int nowMon = (t.getDate().getYear() + 1900) * 12 + t.getDate().getMonth(); if (nowMon > begin && nowMon < end && !t.getDatas().isEmpty()) set.add(t); } ActionContext ctx = ActionContext.getContext(); ctx.put("teams", set); ctx.put("date1", date); ctx.put("date2", date); return "success"; }
public void testCookieCreation() throws Exception { prepare(I18nInterceptor.DEFAULT_COOKIE_PARAMETER, "da_DK"); final Cookie cookie = new Cookie(I18nInterceptor.DEFAULT_COOKIE_ATTRIBUTE, "da_DK"); HttpServletResponse response = EasyMock.createMock(HttpServletResponse.class); response.addCookie(CookieMatcher.eqCookie(cookie)); EasyMock.replay(response); ac.put(StrutsStatics.HTTP_RESPONSE, response); interceptor.intercept(mai); EasyMock.verify(response); Locale denmark = new Locale("da", "DK"); assertNotNull(session.get(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE)); // should be stored here assertEquals( denmark, session.get(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE)); // should create a locale object }
@Override public String intercept(ActionInvocation invocation) throws Exception { // 如果是windows环境 表明是测试环境 不需要登录 if (EnvUtil.isWindows()) { return invocation.invoke(); } // 取得请求相关的ActionContext实例 ActionContext ctx = invocation.getInvocationContext(); // 如果是login请求 不拦截 if (invocation.getInvocationContext().getName().equals("login")) { return invocation.invoke(); } Map<String, Object> session = ctx.getSession(); Integer opId = (Integer) session.get("opId"); String opName = (String) session.get("opName"); if (EmptyUtil.isNotEmpty(opId) && EmptyUtil.isNotEmpty(opName)) { return invocation.invoke(); } ctx.put("tip", "你还没有登录"); return Action.LOGIN; }
public String execute() throws Exception { List<UserLable> userLableList = userLableService.getAll(); ActionContext context = ActionContext.getContext(); context.put("userLables", userLableList); return SUCCESS; }
@Override public String intercept(ActionInvocation invocation) throws Exception { ActionContext ctx = ActionContext.getContext(); Map session = ctx.getSession(); String actionName = invocation.getInvocationContext().getName(); System.out.println("ActionName:" + actionName); User user = (User) session.get("user"); if (user != null && user.isIsreg() && actionName.equals("student_load_for_reg")) { ActionContext.getContext().put("tip", "操作失败,您已激活用户,无需重复激活"); return "error"; } if (user != null && !user.isIsreg() && !actionName.equals("student_load_for_reg")) { ActionContext.getContext().put("tip", "操作失败,如果您还未激活用户,请先用学号和身份证号激活"); return "login"; } if (actionName.equals("select_answer") && user == null) { ActionContext.getContext().put("tip", "请先登录再测评"); return "login"; } if (actionName.equals("profile")) { String sid = ((String[]) invocation.getInvocationContext().getParameters().get("student.sid"))[0]; // System.out.println(sid); if (user == null) { ActionContext.getContext().put("tip", "请先登录"); return "login"; } else { if (user.getType().equals("student") && !user.getSid().equals(sid)) { ActionContext.getContext().put("tip", "获取信息失败,您只能获取自己的信息"); return "error"; } } } if (actionName.endsWith("load_answer_modify")) { if (user == null) { ActionContext.getContext().put("tip", "请先登录,再对您的测评结果进行查看修改"); return "login"; } } if (actionName.endsWith("answer_modify")) { if (user == null) { ActionContext.getContext().put("tip", "请先登录,再对您的测评结果进行修改"); return "login"; } } if (actionName.equals("student_load_for_modify")) { String sid = ((String[]) invocation.getInvocationContext().getParameters().get("student.sid"))[0]; if (user == null) { ActionContext.getContext().put("tip", "请先登录,再对您的基本信息进行修改"); return "login"; } else { if (user.getType().equals("student") && !user.getSid().equals(sid)) { ActionContext.getContext().put("tip", "获取信息失败,您只能获取自己的信息"); return "error"; } } } if (actionName.equals("student_load_for_reg")) { String sid = ((String[]) invocation.getInvocationContext().getParameters().get("student.sid"))[0]; if (user == null) { ActionContext.getContext().put("tip", "如果您还未激活账号,请先用学号和身份证号验证"); return "login"; } else { // System.out.println(sid+":"+user.getType()); if (user.getType().equals("student") && !user.getSid().equals(sid)) { ActionContext.getContext().put("tip", "只能激活您自己的账号哦,亲"); return "login"; } } } if (user != null) { return invocation.invoke(); } ctx.put("tip", "您还没有登录,请先登录"); return Action.LOGIN; }