List of usage examples for javax.servlet.http HttpServletResponse sendRedirect
public void sendRedirect(String location) throws IOException;
From source file:info.rmapproject.webapp.auth.AuthenticationInterceptor.java
@Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { HandlerMethod hm = (HandlerMethod) handler; Method method = hm.getMethod(); if (method.getDeclaringClass().isAnnotationPresent(Controller.class)) { if (method.isAnnotationPresent(LoginRequired.class)) { OAuthProviderAccount account = (OAuthProviderAccount) request.getSession() .getAttribute(ACCOUNT_SESSION_ATTRIBUTE); if (account == null) { response.sendRedirect(request.getContextPath() + USER_LOGIN_PATH); return false; }/*from w w w . j a v a 2 s .com*/ User user = (User) request.getSession().getAttribute(USER_SESSION_ATTRIBUTE); if ((!method.getName().equals(SIGNUPFORM_METHOD) && !method.getName().equals(ADDUSER_METHOD)) && (user == null || user.getUserId() == 0)) { //new user, get them signed up! response.sendRedirect(request.getContextPath() + USER_SIGNUP_PATH); return false; } } } return true; }
From source file:pivotal.au.se.gemfirexdweb.controller.ConstraintController.java
@RequestMapping(value = "/constraints", method = RequestMethod.GET) public String showConstraints(Model model, HttpServletResponse response, HttpServletRequest request, HttpSession session) throws Exception { int startAtIndex = 0, endAtIndex = 0; javax.servlet.jsp.jstl.sql.Result fkInfoResult; String schema = null;// w ww. j a v a2 s . c o m 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; } } } logger.debug("Received request to show constraints"); ConstraintDAO conDAO = GemFireXDWebDAOFactory.getConstraintDAO(); Result result = new Result(); String conAction = request.getParameter("conAction"); String selectedSchema = request.getParameter("selectedSchema"); logger.debug("selectedSchema = " + selectedSchema); if (selectedSchema != null) { schema = selectedSchema; } else { schema = (String) session.getAttribute("schema"); } logger.debug("schema = " + schema); if (conAction != null) { logger.debug("conAction = " + conAction); if (conAction.equalsIgnoreCase("FKINFO")) { fkInfoResult = conDAO.getFKInfo(schema, (String) request.getParameter("constraintId"), (String) session.getAttribute("user_key")); model.addAttribute("fkInfoResult", fkInfoResult); model.addAttribute("constraintname", (String) request.getParameter("constraintName")); } else { result = null; result = conDAO.simpleconstraintCommand(schema, (String) request.getParameter("tabName"), (String) request.getParameter("constraintName"), conAction, (String) session.getAttribute("user_key")); model.addAttribute("result", result); } } List<Constraint> cons = conDAO.retrieveConstraintList(schema, null, (String) session.getAttribute("user_key")); model.addAttribute("records", cons.size()); model.addAttribute("estimatedrecords", cons.size()); UserPref userPref = (UserPref) session.getAttribute("prefs"); if (cons.size() <= userPref.getRecordsToDisplay()) { model.addAttribute("cons", cons); } 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 > cons.size()) { endAtIndex = cons.size(); } } else { endAtIndex = userPref.getRecordsToDisplay(); } List subList = cons.subList(startAtIndex, endAtIndex); model.addAttribute("cons", 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/constraints.jsp return "constraints"; }
From source file:Controllers.EditItem.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request/* ww w. j a va2 s . c om*/ * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String id = null; String name = null; String itemCode = null; String price = null; String quantity = null; String category = null; String image = null; HttpSession session = request.getSession(true); User user = (User) session.getAttribute("user"); if (user == null) { response.sendRedirect("login"); return; } // request.getServletContext().getRealPath("/uploads"); String path = request.getServletContext().getRealPath("/uploads"); System.out.println(path); if (ServletFileUpload.isMultipartContent(request)) { try { List<FileItem> multiparts = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request); for (FileItem item : multiparts) { if (!item.isFormField()) { String fileName = new File(item.getName()).getName(); // new File(path).mkdirs(); File directory = new File(path + File.separator + fileName); image = fileName; item.write(directory); } else { if ("name".equals(item.getFieldName())) { name = item.getString(); } else if ("id".equals(item.getFieldName())) { id = item.getString(); } else if ("itemCode".equals(item.getFieldName())) { itemCode = item.getString(); } else if ("price".equals(item.getFieldName())) { price = item.getString(); } else if ("quantity".equals(item.getFieldName())) { quantity = item.getString(); } else if ("category".equals(item.getFieldName())) { category = item.getString(); } } } //File uploaded successfully System.out.println("done"); } catch (Exception ex) { ex.printStackTrace(); } } boolean status = ItemRepository.editItem(name, itemCode, price, quantity, category, image, id); String message; System.out.println(status); if (status) { message = "Item saved successfully"; response.sendRedirect("dashboard"); } else { message = "Item not saved !!"; request.setAttribute("message", message); request.getRequestDispatcher("dashboard/addItem.jsp").forward(request, response); } }
From source file:com.activecq.tools.auth.impl.PluggableAuthenticationHandlerImpl.java
@Override public boolean requestCredentials(HttpServletRequest request, HttpServletResponse response) { if (!this.enabled) { return false; }/*from www. j a v a2 s . co m*/ if (StringUtils.isBlank(requestCredentialsRedirect) || StringUtils.equals(requestCredentialsRedirect, "null")) { return false; } else { try { response.sendRedirect(requestCredentialsRedirect); return true; } catch (IOException ex) { java.util.logging.Logger.getLogger(PluggableAuthenticationHandlerImpl.class.getName()) .log(Level.SEVERE, null, ex); return false; } } }
From source file:CategoryServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from www . j av a2s. c o m*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { /* TODO output your page here. You may use following sample code. */ try { BufferedReader br = null; String price_range = request.getParameter("price_range"); System.out.println(price_range); if (price_range.equals("null")) response.sendRedirect("Home.html"); else { HttpSession session = request.getSession(); session.setAttribute("price_range", price_range); br = new BufferedReader(new FileReader("Path to your questionnaire files")); } WriteQuestionnaireJSON obj = new WriteQuestionnaireJSON(); String line; int i = 1; while ((line = br.readLine()) != null) { obj.buildJSON(line + "?", "Q" + i); i++; } JSONObject x = obj.write(); out.println(x.toJSONString()); } catch (Exception e) { out.println(e.getMessage()); } } }
From source file:com.iservport.auth.SecurityWebConfig.java
/** * Intercepta erros de autenticao./*from w w w . jav a2s . c om*/ */ @Bean public AuthenticationFailureHandler authenticationFailureHandler() { return new AuthenticationFailureHandler() { @Override public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException { String exceptionToken = exception.getMessage().trim().toLowerCase().replace(" ", ""); int type = 0; if (exceptionToken.contains("badcredentials")) { type = 1; } else if (exceptionToken.contains("unabletoextractvaliduser")) { type = 2; } response.sendRedirect(request.getContextPath() + "/login/error?type=" + type); } }; }
From source file:com.globalsight.everest.webapp.pagehandler.administration.projects.ProjectMainHandler.java
/** * Remove a project./* ww w. j a va2 s . c o m*/ */ private void removeProject(HttpServletRequest request, HttpServletResponse response) { SessionManager sessionMgr = getSessionManager(request); try { String ids = (String) request.getParameter(RADIO_BUTTON); if (ids == null || request.getMethod().equalsIgnoreCase(REQUEST_METHOD_GET)) { response.sendRedirect("/globalsight/ControlServlet?activityName=projects"); return; } long longProjectId = -1; String[] idarr = ids.trim().split(" "); for (String projectId : idarr) { if ("on".equals(projectId)) continue; try { longProjectId = (new Integer(projectId)).longValue(); } catch (Exception e) { s_logger.error("Wrong project id : " + projectId); } String error_msg = checkProjectDependency(longProjectId); if (error_msg != null && !"".equals(error_msg.trim())) { throw new Exception(error_msg); } // delete user from "project_user" table and set project // is_active = 'N' else { doDeleteProject(longProjectId); } } sessionMgr.clear(); } catch (Exception e) { sessionMgr.setAttribute(WebAppConstants.PROJECT_ERROR, e.getMessage()); } }
From source file:pivotal.au.se.gemfirexdweb.controller.CreateTableController.java
@RequestMapping(value = "/createtable", method = RequestMethod.GET) public String createTable(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 {/* w w w. ja v a 2 s . com*/ 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; } } } logger.debug("Received request to create a new table"); session.setAttribute("numColumns", "0"); session.setAttribute("tabName", "newtable"); model.addAttribute("numColumns", "0"); DiskStoreDAO dsDAO = GemFireXDWebDAOFactory.getDiskStoreDAO(); HdfsStoreDAO hdfsDAO = GemFireXDWebDAOFactory.getHdfsStoreDAO(); List<DiskStore> dsks = dsDAO.retrieveDiskStoreForCreateList((String) session.getAttribute("user_key")); List<HdfsStore> hdfs = hdfsDAO.retrieveHdfsStoreForCreateList((String) session.getAttribute("user_key")); model.addAttribute("diskstores", dsks); model.addAttribute("hdfsstores", hdfs); model.addAttribute("tableAttribute", new NewTable()); // This will resolve to /WEB-INF/jsp/create-table.jsp return "create-table"; }
From source file:pivotal.au.se.gemfirexdweb.controller.TriggerController.java
@RequestMapping(value = "/triggers", method = RequestMethod.POST) public String performTriggerAction(Model model, HttpServletResponse response, HttpServletRequest request, HttpSession session) throws Exception { String schema = null;/*from w ww. ja v a 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<Trigger> triggers = null; logger.debug("Received request to perform an action on the riggers"); String selectedSchema = request.getParameter("selectedSchema"); logger.debug("selectedSchema = " + selectedSchema); if (selectedSchema != null) { schema = selectedSchema; } else { schema = (String) session.getAttribute("schema"); } logger.debug("schema = " + schema); TriggerDAO triggerDAO = GemFireXDWebDAOFactory.getTriggerDAO(); if (request.getParameter("search") != null) { triggers = triggerDAO.retrieveTriggerList(schema, (String) request.getParameter("search"), (String) session.getAttribute("user_key")); model.addAttribute("search", (String) request.getParameter("search")); } else { String[] tableList = request.getParameterValues("selected_trigger[]"); 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 trigger : tableList) { result = null; result = triggerDAO.simpletriggerCommand(schema, trigger, commandStr, (String) session.getAttribute("user_key")); al.add(result); } model.addAttribute("arrayresult", al); } triggers = triggerDAO.retrieveTriggerList(schema, null, (String) session.getAttribute("user_key")); } model.addAttribute("records", triggers.size()); model.addAttribute("estimatedrecords", triggers.size()); UserPref userPref = (UserPref) session.getAttribute("prefs"); if (triggers.size() <= userPref.getRecordsToDisplay()) { model.addAttribute("triggers", triggers); } 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 > triggers.size()) { endAtIndex = triggers.size(); } } else { endAtIndex = userPref.getRecordsToDisplay(); } List subList = triggers.subList(startAtIndex, endAtIndex); model.addAttribute("triggers", 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/triggers.jsp return "triggers"; }
From source file:edu.duke.cabig.c3pr.web.study.AmendStudyController.java
@Override protected ModelAndView processFinish(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception { // ModelAndView modelAndView = new ModelAndView(new RedirectView("searchStudy")); // return modelAndView; Study study = ((StudyWrapper) command).getStudy(); if (request.getParameter("_action").equals("amendment")) { study = studyRepository.applyAmendment(study.getIdentifiers()); }/* w w w .j ava 2 s . c o m*/ ((StudyWrapper) command).setStudy(study); response.sendRedirect("confirm?studyId=" + study.getId()); return null; }