Java Code Examples for org.apache.struts2.ServletActionContext#getResponse()
The following examples show how to use
org.apache.struts2.ServletActionContext#getResponse() .
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: QuestionManageAction.java From OnLineTest with Apache License 2.0 | 6 votes |
public String getChoice(){ HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType("application/json;charset=utf-8"); Choice choice = new Choice(); choice.setChoiceId(choiceId); Choice newChoice = questionService.getChoiceById(choice); JsonConfig jsonConfig = new JsonConfig(); jsonConfig.setJsonPropertyFilter(new PropertyFilter() { public boolean apply(Object obj, String name, Object value) { if(obj instanceof Set||name.equals("subjects") || name.equals("choices") || name.equals("judges")){//过滤掉集合 return true; }else{ return false; } } }); JSONObject jsonObject = JSONObject.fromObject(newChoice,jsonConfig); try { response.getWriter().print(jsonObject); } catch (IOException e) { throw new RuntimeException(e.getMessage()); } return null; }
Example 2
Source File: StreamActionSupport.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public String execute() throws Exception { HttpServletResponse response = ServletActionContext.getResponse(); String contentType = getContentType(); boolean disallowCache = disallowCache(); String filename = getFilename(); boolean attachment = attachment(); ContextUtils.configureResponse( response, contentType, disallowCache, filename, attachment ); log.debug( "Content type: " + contentType + ", disallow cache: " + disallowCache + ", filename: " + filename + ", attachment: " + attachment ); try ( OutputStream out = response.getOutputStream() ) { return execute( response, out ); } }
Example 3
Source File: BookAction.java From LibrarySystem with Apache License 2.0 | 6 votes |
/** * 得到图书类型的集合 * ajax请求该方法 * 返回图书类型集合的json对象 * @return */ public String getAllBookTypes(){ HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType("application/json;charset=utf-8"); List<BookType> allBookTypes = bookTypeService.getAllBookTypes(); String json = JSONArray.fromObject(allBookTypes).toString();//List------->JSONArray try { response.getWriter().print(json); } catch (IOException e) { throw new RuntimeException(e.getMessage()); } return null; }
Example 4
Source File: GridCsvResult.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void execute( ActionInvocation invocation ) throws Exception { // --------------------------------------------------------------------- // Get grid // --------------------------------------------------------------------- Grid _grid = (Grid) invocation.getStack().findValue( "grid" ); grid = _grid != null ? _grid : grid; // --------------------------------------------------------------------- // Configure response // --------------------------------------------------------------------- HttpServletResponse response = ServletActionContext.getResponse(); String filename = CodecUtils.filenameEncode( StringUtils.defaultIfEmpty( grid.getTitle(), DEFAULT_FILENAME ) ) + ".csv"; ContextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_CSV, true, filename, true ); // --------------------------------------------------------------------- // Write CSV to output stream // --------------------------------------------------------------------- GridUtils.toCsv( grid, response.getWriter() ); }
Example 5
Source File: GridJrxmlResult.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override @SuppressWarnings("unchecked") public void execute( ActionInvocation invocation ) throws Exception { // --------------------------------------------------------------------- // Get grid // --------------------------------------------------------------------- Grid _grid = (Grid) invocation.getStack().findValue( "grid" ); grid = _grid != null ? _grid : grid; Map<Object, Object> _params = (Map<Object, Object>) invocation.getStack().findValue( "params" ); params = _params != null ? _params : params; // --------------------------------------------------------------------- // Configure response // --------------------------------------------------------------------- HttpServletResponse response = ServletActionContext.getResponse(); Writer writer = response.getWriter(); String filename = CodecUtils.filenameEncode( StringUtils.defaultIfEmpty( grid.getTitle(), DEFAULT_FILENAME ) ) + ".jrxml"; ContextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_XML, true, filename, true ); // --------------------------------------------------------------------- // Write jrxml based on Velocity template // --------------------------------------------------------------------- GridUtils.toJrxml( grid, params, writer ); }
Example 6
Source File: GridJasperResult.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override @SuppressWarnings("unchecked") public void execute( ActionInvocation invocation ) throws Exception { // --------------------------------------------------------------------- // Get grid // --------------------------------------------------------------------- Grid _grid = (Grid) invocation.getStack().findValue( "grid" ); grid = _grid != null ? _grid : grid; Map<String, Object> _params = (Map<String, Object>) invocation.getStack().findValue( "params" ); params = _params != null ? _params : params; // --------------------------------------------------------------------- // Configure response // --------------------------------------------------------------------- HttpServletResponse response = ServletActionContext.getResponse(); String filename = CodecUtils.filenameEncode( StringUtils.defaultIfEmpty( grid.getTitle(), DEFAULT_FILENAME ) ) + ".pdf"; ContextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_PDF, true, filename, false ); // --------------------------------------------------------------------- // Write jrxml based on Velocity template // --------------------------------------------------------------------- GridUtils.toJasperReport( grid, params, response.getOutputStream() ); }
Example 7
Source File: CacheInterceptor.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public String intercept( ActionInvocation invocation ) throws Exception { HttpServletRequest request = ServletActionContext.getRequest(); HttpServletResponse response = ServletActionContext.getResponse(); if ( HttpMethod.GET == HttpMethod.resolve( request.getMethod() ) ) { response.setHeader( "Cache-Control", CacheControl.maxAge( seconds, TimeUnit.SECONDS ).cachePublic().getHeaderValue() ); } return invocation.invoke(); }
Example 8
Source File: LoginedCheckInterceptor.java From scada with MIT License | 5 votes |
@Override public String intercept(ActionInvocation invocation) throws Exception { //ȡ�������URL String url = ServletActionContext.getRequest().getRequestURL().toString(); HttpServletResponse response=ServletActionContext.getResponse(); response.setHeader("Pragma","No-cache"); response.setHeader("Cache-Control","no-cache"); response.setHeader("Cache-Control", "no-store"); response.setDateHeader("Expires",0); User user = null; //�Ե�¼��ע������ֱ�ӷ���,�������� if (url.indexOf("loginAction_loginValidate")!=-1 || url.indexOf("loginAction_safeExit")!=-1 ){ return invocation.invoke(); } else{ //��֤Session�Ƿ���� if(!ServletActionContext.getRequest().isRequestedSessionIdValid()){ //session����,ת��session������ʾҳ,������ת����¼ҳ�� return "tologin"; } else{ user = (User)ServletActionContext.getRequest().getSession().getAttribute("global_user"); //��֤�Ƿ��Ѿ���¼ if (user==null){ //��δ��¼,��ת����¼ҳ�� return "tologin"; }else{ return invocation.invoke(); } } } }
Example 9
Source File: BookManageAction.java From LibrarySystem with Apache License 2.0 | 5 votes |
/** * 得到指定图书编号的图书信息 * ajax请求该方法 * 返回该图书信息的json对象 * @return */ public String getBook(){ HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType("application/json;charset=utf-8"); Book book = new Book(); book.setBookId(bookId); Book newBook = bookService.getBookById(book);//得到图书 JsonConfig jsonConfig = new JsonConfig(); jsonConfig.setJsonPropertyFilter(new PropertyFilter() { public boolean apply(Object obj, String name, Object value) { if(obj instanceof Authorization||name.equals("authorization")){ return true; }else{ return false; } } }); JSONObject jsonObject = JSONObject.fromObject(newBook,jsonConfig); try { response.getWriter().print(jsonObject); } catch (IOException e) { throw new RuntimeException(e.getMessage()); } return null; }
Example 10
Source File: NoticeAction.java From CompanyWebsite with Apache License 2.0 | 5 votes |
public String getNotice() { HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType("application/json;charset=utf-8"); Notice notice = new Notice(); notice.setNid(id); Notice newNotice = noticeService.getNoticeById(notice); JSONObject jsonObject = JSONObject.fromObject(newNotice); try { response.getWriter().print(jsonObject); } catch (IOException e) { throw new RuntimeException(e.getMessage()); } return null; }
Example 11
Source File: CustomImageBytesResult.java From aliada-tool with GNU General Public License v3.0 | 5 votes |
@Override public void execute(final ActionInvocation invocation) throws Exception { ImageAction action = (ImageAction) invocation.getAction(); HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType(action.getCustomContentType()); response.getOutputStream().write(action.getCustomImageInBytes()); response.getOutputStream().flush(); }
Example 12
Source File: ArticleManageAction.java From CompanyWebsite with Apache License 2.0 | 5 votes |
public String getArticle(){ HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType("application/json;charset=utf-8"); Article article = new Article(); article.setAid(id); Article newArticle = articleService.getArticleById(article); JSONObject jsonObject = JSONObject.fromObject(newArticle); try { response.getWriter().print(jsonObject); } catch (IOException e) { throw new RuntimeException(e.getMessage()); } return null; }
Example 13
Source File: BookAction.java From sdudoc with MIT License | 5 votes |
@Action("checkDynasty") public String checkDynasty(){ dynastyList=bookService.checkDynasty(); JSONArray jsonArray = JSONArray.fromObject(dynastyList); //ajax返回客户端 jsonArray.toString(); HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType("application/html;charset=UTF-8"); try { response.getWriter().write(jsonArray.toString()); } catch (IOException e) { e.printStackTrace(); } return null; }
Example 14
Source File: TeacherManageAction.java From OnLineTest with Apache License 2.0 | 5 votes |
public String getTeacher(){ HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType("application/json;charset=utf-8"); Teacher teacher = new Teacher(); teacher.setTeacherId(teacherId); Teacher newTeacher = teacherService.getTeacherById(teacher); JSONObject jsonObject = JSONObject.fromObject(newTeacher); try { response.getWriter().print(jsonObject); } catch (IOException e) { throw new RuntimeException(e.getMessage()); } return null; }
Example 15
Source File: UserManageAction.java From CompanyWebsite with Apache License 2.0 | 5 votes |
public String getUser() { HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType("application/json;charset=utf-8"); User user = new User(); user.setUserId(id); User newUser = userService.getUserById(user); JSONObject jsonObject = JSONObject.fromObject(newUser); try { response.getWriter().print(jsonObject); } catch (IOException e) { throw new RuntimeException(e.getMessage()); } return null; }
Example 16
Source File: StudentManageAction.java From OnLineTest with Apache License 2.0 | 5 votes |
public String getState(){ Student student = new Student(); student.setStudentId(studentId); Subject subject = new Subject(); subject.setSubjectId(subjectId); Score score = scoreService.getScore(student, subject); int state = 0; if(score!=null){ //该试卷已经做过了 state = -2; }else{ //该试卷没做过,或者正在做着试卷 //判断是否正在做试卷 Student studentById = studentService.getStudentById(student); //锁住的状态是否等于当前科目,除了当前科目可以继续考试,不能进行其他考试 if(!(studentById.getLockState().equals(subject.getSubjectId()) || studentById.getLockState().equals(0))){ //正在考试 state = -1; }else{ //允许进入做试卷 state = 1; //修改学生锁住状态,设置为当前考试科目 studentById.setLockState(subject.getSubjectId()); studentService.updateStudent(studentById); } } HttpServletResponse response = ServletActionContext.getResponse(); try { response.getWriter().print(state); } catch (IOException e) { throw new RuntimeException(e.getMessage()); } return null; }
Example 17
Source File: ChartResult.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Executes the result. Writes the given chart as a PNG to the servlet * output stream. * * @param invocation an encapsulation of the action execution state. * @throws Exception if an error occurs when creating or writing the chart * to the servlet output stream. */ @Override public void execute( ActionInvocation invocation ) throws Exception { JFreeChart stackChart = (JFreeChart) invocation.getStack().findValue( "chart" ); chart = stackChart != null ? stackChart : chart; Integer stackHeight = (Integer) invocation.getStack().findValue( "height" ); height = stackHeight != null && stackHeight > 0 ? stackHeight : height != null ? height : DEFAULT_HEIGHT; Integer stackWidth = (Integer) invocation.getStack().findValue( "width" ); width = stackWidth != null && stackWidth > 0 ? stackWidth : width != null ? width : DEFAULT_WIDTH; String stackFilename = (String) invocation.getStack().findValue( "filename" ); filename = StringUtils.defaultIfEmpty( stackFilename, DEFAULT_FILENAME ); if ( chart == null ) { log.warn( "No chart found" ); return; } HttpServletResponse response = ServletActionContext.getResponse(); ContextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_PNG, true, filename, false ); OutputStream os = response.getOutputStream(); ChartUtils.writeChartAsPNG( os, chart, width, height ); os.flush(); }
Example 18
Source File: ReaderTypeManageAction.java From LibrarySystem with Apache License 2.0 | 5 votes |
/** * 得到指定的读者类型信息 * @return */ public String getReaderType(){ HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType("application/json;charset=utf-8"); ReaderType readerType = new ReaderType(); readerType.setReaderTypeId(id); ReaderType newReaderType = readerTypeService.getTypeById(readerType); JSONObject jsonObject = JSONObject.fromObject(newReaderType); try { response.getWriter().print(jsonObject); } catch (IOException e) { throw new RuntimeException(e.getMessage()); } return null; }
Example 19
Source File: BaseAction.java From csustRepo with MIT License | 4 votes |
public HttpServletResponse getResponse(){ return ServletActionContext.getResponse(); }
Example 20
Source File: GridXlsResult.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override @SuppressWarnings( "unchecked" ) public void execute( ActionInvocation invocation ) throws Exception { // --------------------------------------------------------------------- // Get grid // --------------------------------------------------------------------- Grid _grid = (Grid) invocation.getStack().findValue( "grid" ); grid = _grid != null ? _grid : grid; List<Grid> _grids = (List<Grid>) invocation.getStack().findValue( "grids" ); grids = _grids != null ? _grids : grids; // --------------------------------------------------------------------- // Configure response // --------------------------------------------------------------------- HttpServletResponse response = ServletActionContext.getResponse(); OutputStream out = response.getOutputStream(); String filename = filenameEncode( defaultIfEmpty( grid != null ? grid.getTitle() : grids.iterator().next().getTitle(), DEFAULT_NAME ) ) + ".xls"; ContextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_EXCEL, true, filename, true ); // --------------------------------------------------------------------- // Create workbook and write to output stream // --------------------------------------------------------------------- if ( grid != null ) { GridUtils.toXls( grid, out ); } else { GridUtils.toXls( grids, out ); } }