List of usage examples for javax.servlet.http HttpServletResponse sendRedirect
public void sendRedirect(String location) throws IOException;
From source file:pivotal.au.se.gemfirexdweb.controller.ViewController.java
@RequestMapping(value = "/views", method = RequestMethod.POST) public String performTableAction(Model model, HttpServletResponse response, HttpServletRequest request, HttpSession session) throws Exception { String schema = null;/*w w w.j a va 2 s. c o m*/ int startAtIndex = 0, endAtIndex = 0; if (session.getAttribute("user_key") == null) { logger.debug("user_key is null new Login required"); response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login"); return null; } else { Connection conn = AdminUtil.getConnection((String) session.getAttribute("user_key")); if (conn == null) { response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login"); return null; } else { if (conn.isClosed()) { response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login"); return null; } } } Result result = new Result(); List<View> views = null; logger.debug("Received request to perform an action on the views"); String selectedSchema = request.getParameter("selectedSchema"); logger.debug("selectedSchema = " + selectedSchema); if (selectedSchema != null) { schema = selectedSchema; } else { schema = (String) session.getAttribute("schema"); } logger.debug("schema = " + schema); ViewDAO viewDAO = GemFireXDWebDAOFactory.getViewDAO(); if (request.getParameter("search") != null) { views = viewDAO.retrieveViewList(schema, (String) request.getParameter("search"), (String) session.getAttribute("user_key")); model.addAttribute("search", (String) request.getParameter("search")); } else { String[] tableList = request.getParameterValues("selected_view[]"); String commandStr = request.getParameter("submit_mult"); logger.debug("tableList = " + Arrays.toString(tableList)); logger.debug("command = " + commandStr); // start actions now if tableList is not null if (tableList != null) { List al = new ArrayList<Result>(); for (String view : tableList) { result = null; result = viewDAO.simpleviewCommand(schema, view, commandStr, (String) session.getAttribute("user_key")); al.add(result); } model.addAttribute("arrayresult", al); } views = viewDAO.retrieveViewList(schema, null, (String) session.getAttribute("user_key")); } model.addAttribute("records", views.size()); model.addAttribute("estimatedrecords", views.size()); UserPref userPref = (UserPref) session.getAttribute("prefs"); if (views.size() <= userPref.getRecordsToDisplay()) { model.addAttribute("views", views); } else { if (request.getParameter("startAtIndex") != null) { startAtIndex = Integer.parseInt(request.getParameter("startAtIndex")); } if (request.getParameter("endAtIndex") != null) { endAtIndex = Integer.parseInt(request.getParameter("endAtIndex")); if (endAtIndex > views.size()) { endAtIndex = views.size(); } } else { endAtIndex = userPref.getRecordsToDisplay(); } List subList = views.subList(startAtIndex, endAtIndex); model.addAttribute("views", subList); } model.addAttribute("startAtIndex", startAtIndex); model.addAttribute("endAtIndex", endAtIndex); model.addAttribute("schemas", GemFireXDWebDAOUtil.getAllSchemas((String) session.getAttribute("user_key"))); model.addAttribute("chosenSchema", schema); // This will resolve to /WEB-INF/jsp/views.jsp return "views"; }
From source file:com.wms.multitenant.tenant.interceptor.TenantIdentifierInterceptorAdapter.java
@Override public boolean preHandle(HttpServletRequest req, HttpServletResponse res, Object handler) throws Exception { Map<String, Object> pathVars = (Map<String, Object>) req .getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE); if (pathVars.containsKey("tenantId")) { String tenantId = pathVars.get("tenantId").toString(); Optional<Tenant> thisTenant = tenantRepo.findByTenantKey(tenantId); if (thisTenant.isPresent()) { req.setAttribute("Current_Tenant", thisTenant.get().getTenantKey()); return true; } else {/* www . ja va 2s .co m*/ res.sendRedirect(req.getContextPath() + "/signUp"); return false; } } else { return true; } }
From source file:pivotal.au.se.gemfirexdweb.controller.IndexController.java
@RequestMapping(value = "/indexes", method = RequestMethod.POST) public String performIndexAction(Model model, HttpServletResponse response, HttpServletRequest request, HttpSession session) throws Exception { String schema = null;/*from w w w .ja va 2 s. c o m*/ int startAtIndex = 0, endAtIndex = 0; if (session.getAttribute("user_key") == null) { logger.debug("user_key is null new Login required"); response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login"); return null; } else { Connection conn = AdminUtil.getConnection((String) session.getAttribute("user_key")); if (conn == null) { response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login"); return null; } else { if (conn.isClosed()) { response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login"); return null; } } } Result result = new Result(); List<Index> indexes = null; logger.debug("Received request to perform an action on the indexes"); String selectedSchema = request.getParameter("selectedSchema"); logger.debug("selectedSchema = " + selectedSchema); if (selectedSchema != null) { schema = selectedSchema; } else { schema = (String) session.getAttribute("schema"); } logger.debug("schema = " + schema); IndexDAO indexDAO = GemFireXDWebDAOFactory.getIndexDAO(); if (request.getParameter("search") != null) { indexes = indexDAO.retrieveIndexList(schema, (String) request.getParameter("search"), (String) session.getAttribute("user_key")); model.addAttribute("search", (String) request.getParameter("search")); } else { String[] tableList = request.getParameterValues("selected_idx[]"); String commandStr = request.getParameter("submit_mult"); logger.debug("tableList = " + Arrays.toString(tableList)); logger.debug("command = " + commandStr); // start actions now if tableList is not null if (tableList != null) { List al = new ArrayList<Result>(); for (String index : tableList) { result = null; result = indexDAO.simpleindexCommand(schema, index, commandStr, (String) session.getAttribute("user_key")); al.add(result); } model.addAttribute("arrayresult", al); } indexes = indexDAO.retrieveIndexList(schema, null, (String) session.getAttribute("user_key")); } model.addAttribute("records", indexes.size()); model.addAttribute("estimatedrecords", indexes.size()); UserPref userPref = (UserPref) session.getAttribute("prefs"); if (indexes.size() <= userPref.getRecordsToDisplay()) { model.addAttribute("indexes", indexes); } else { if (request.getParameter("startAtIndex") != null) { startAtIndex = Integer.parseInt(request.getParameter("startAtIndex")); } if (request.getParameter("endAtIndex") != null) { endAtIndex = Integer.parseInt(request.getParameter("endAtIndex")); if (endAtIndex > indexes.size()) { endAtIndex = indexes.size(); } } else { endAtIndex = userPref.getRecordsToDisplay(); } List subList = indexes.subList(startAtIndex, endAtIndex); model.addAttribute("indexes", subList); } model.addAttribute("startAtIndex", startAtIndex); model.addAttribute("endAtIndex", endAtIndex); model.addAttribute("schemas", GemFireXDWebDAOUtil.getAllSchemas((String) session.getAttribute("user_key"))); model.addAttribute("chosenSchema", schema); // This will resolve to /WEB-INF/jsp/indexes.jsp return "indexes"; }
From source file:com.surfs.storage.web.filter.LoginFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest req = (HttpServletRequest) request; HttpServletResponse resp = (HttpServletResponse) response; String uriStr = req.getRequestURI(); String path = req.getContextPath(); System.out.println(uriStr);//ww w . j ava 2 s.c o m if (excludes_Pattern != null) { for (Pattern exclude_Pattern : excludes_Pattern) { if (exclude_Pattern.matcher(uriStr).find()) { chain.doFilter(request, response); return; } } } Object user = req.getSession().getAttribute("user"); if (user == null) { resp.sendRedirect(path + "/home.jsp?status=access_error"); return; } chain.doFilter(request, response); }
From source file:pivotal.au.se.gemfirexdweb.controller.TableController.java
@RequestMapping(value = "/tables", method = RequestMethod.POST) public String performTableAction(Model model, HttpServletResponse response, HttpServletRequest request, HttpSession session) throws Exception { if (session.getAttribute("user_key") == null) { logger.debug("user_key is null new Login required"); response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login"); return null; } else {/*from w w w .j a v a 2 s .co m*/ Connection conn = AdminUtil.getConnection((String) session.getAttribute("user_key")); if (conn == null) { response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login"); return null; } else { if (conn.isClosed()) { response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login"); return null; } } } int startAtIndex = 0, endAtIndex = 0; String schema = null; Result result = new Result(); List<Table> tbls = null; logger.debug("Received request to perform an action on the tables"); TableDAO tableDAO = GemFireXDWebDAOFactory.getTableDAO(); String selectedSchema = request.getParameter("selectedSchema"); logger.debug("selectedSchema = " + selectedSchema); if (selectedSchema != null) { schema = selectedSchema; } else { schema = (String) session.getAttribute("schema"); } logger.debug("schema = " + schema); String viewType = request.getParameter("viewType"); if (viewType == null) { viewType = "ORDINARY"; } logger.debug("viewType = " + viewType); if (request.getParameter("search") != null) { tbls = tableDAO.retrieveTableList(schema, (String) request.getParameter("search"), (String) session.getAttribute("user_key"), viewType); model.addAttribute("search", (String) request.getParameter("search")); } else { String[] tableList = request.getParameterValues("selected_tbl[]"); String commandStr = request.getParameter("submit_mult"); logger.debug("tableList = " + Arrays.toString(tableList)); logger.debug("command = " + commandStr); // start actions now if tableList is not null if (tableList != null) { List al = new ArrayList<Result>(); for (String table : tableList) { result = null; result = tableDAO.simpletableCommand(schema, table, commandStr, (String) session.getAttribute("user_key")); al.add(result); } model.addAttribute("arrayresult", al); } tbls = tableDAO.retrieveTableList(schema, null, (String) session.getAttribute("user_key"), viewType); } model.addAttribute("records", tbls.size()); model.addAttribute("estimatedrecords", tbls.size()); UserPref userPref = (UserPref) session.getAttribute("prefs"); if (tbls.size() <= userPref.getRecordsToDisplay()) { model.addAttribute("tables", tbls); } else { if (request.getParameter("startAtIndex") != null) { startAtIndex = Integer.parseInt(request.getParameter("startAtIndex")); } if (request.getParameter("endAtIndex") != null) { endAtIndex = Integer.parseInt(request.getParameter("endAtIndex")); if (endAtIndex > tbls.size()) { endAtIndex = tbls.size(); } } else { endAtIndex = userPref.getRecordsToDisplay(); } List subList = tbls.subList(startAtIndex, endAtIndex); model.addAttribute("tables", subList); } model.addAttribute("startAtIndex", startAtIndex); model.addAttribute("endAtIndex", endAtIndex); model.addAttribute("schemas", GemFireXDWebDAOUtil.getAllSchemas((String) session.getAttribute("user_key"))); model.addAttribute("chosenSchema", schema); model.addAttribute("viewType", viewType); // This will resolve to /WEB-INF/jsp/tables.jsp return "tables"; }
From source file:edu.cornell.mannlib.vitro.webapp.controller.authenticate.BaseLoginServlet.java
/** * Store an error message in the login bean and go back where we came from. * //from w ww . jav a2 s . c o m * Remove the referring URL from the session after using it. */ protected void complainAndReturnToReferrer(HttpServletRequest req, HttpServletResponse resp, String sessionAttributeForReferrer, Message message) throws IOException { log.debug(message); LoginProcessBean.getBean(req).setMessage(message); String referrer = (String) req.getSession().getAttribute(sessionAttributeForReferrer); log.debug("returning to referrer: " + referrer); if (referrer == null) { referrer = figureHomePageUrl(req); log.debug("returning to home page: " + referrer); } req.getSession().removeAttribute(sessionAttributeForReferrer); resp.sendRedirect(referrer); }
From source file:com.google.zxing.web.DecodeServlet.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (!ServletFileUpload.isMultipartContent(request)) { log.info("File upload was not multipart"); response.sendRedirect("badimage.jspx"); return;/*from w w w. ja va 2 s . c o m*/ } ServletFileUpload upload = new ServletFileUpload(diskFileItemFactory); upload.setFileSizeMax(MAX_IMAGE_SIZE); // Parse the request try { for (FileItem item : upload.parseRequest(request)) { if (!item.isFormField()) { if (item.getSize() <= MAX_IMAGE_SIZE) { log.info("Decoding uploaded file"); try (InputStream is = item.getInputStream()) { processStream(is, request, response); } } else { log.info("Too large"); response.sendRedirect("badimage.jspx"); } break; } } } catch (FileUploadException fue) { log.info(fue.toString()); response.sendRedirect("badimage.jspx"); } }
From source file:com.museum_web.controller.MuseologicalController.java
@RequestMapping("actions/saveMuseological") public void save(MuseologicalObject museum, HttpServletRequest request, HttpServletResponse response) throws Exception { //ModelAndView mv = new ModelAndView("museum/list"); String dateText = request.getParameter("dateText"); DateFormat df = new SimpleDateFormat("dd/MM/yyyy"); Calendar cal = Calendar.getInstance(); cal.setTime(df.parse(dateText));//from ww w . j av a2 s. c o m museum.setDate(cal); if (museum.getId() == 0) { museum.setId(null); new MuseologicalObjectService().createObject(museum); } else { new MuseologicalObjectService().editObject(museum); } response.sendRedirect("../museological"); }
From source file:org.openmrs.module.cloneandexportomrs.web.controller.CloneandexportOpenMRSManageController.java
@RequestMapping(value = "/module/cloneandexportomrs/dumpDb", method = RequestMethod.POST) public void dumpDBonTerminal(ModelMap model, HttpServletResponse response, HttpServletRequest request) { try {/*from w ww . j a v a 2s. c o m*/ Context.getService(CloneAndExportOmrsService.class).dumpDbUsingTerminal(); request.getSession().setAttribute(WebConstants.OPENMRS_MSG_ATTR, "Successfully dumped, go to <a href='downloadDb.form'>downloadDb.form</a> to download it"); } catch (Exception e) { request.getSession().setAttribute(WebConstants.OPENMRS_ERROR_ATTR, e.getMessage()); } try { response.sendRedirect("dumpDb.form"); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.expressflow.servlets.ExecProcessServlet.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { UserService userService = UserServiceFactory.getUserService(); User user = userService.getCurrentUser(); if (user != null) { performRequest(request, response); try {/*from w w w . j a v a 2 s .co m*/ response.getOutputStream().println(new JSONObject().put("result", "success").toString()); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(System.err); } } else { response.sendRedirect(response.encodeRedirectURL(userService.createLoginURL(request.getRequestURI()))); } }