List of usage examples for javax.servlet.http HttpServletResponse sendRedirect
public void sendRedirect(String location) throws IOException;
From source file:net.triptech.buildulator.service.OpenIdAuthenticationSuccessHandler.java
public final void onAuthenticationSuccess(final HttpServletRequest request, final HttpServletResponse response, final Authentication authentication) throws IOException { Person person = Person.findByOpenIdIdentifier(authentication.getName()); if (person != null) { // Transfer any previous projects to the authenticated user transferProjects(request, person); }// ww w . j a v a2 s .c o m response.sendRedirect(request.getContextPath() + "/projects"); }
From source file:de.appsolve.padelcampus.filter.AdminFilter.java
/** * @param request/*from w w w .j a v a2s . c om*/ * @param response * @param chain * @throws java.io.IOException * @throws javax.servlet.ServletException * @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain) */ @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (request instanceof HttpServletRequest && response instanceof HttpServletResponse) { HttpServletRequest httpRequest = (HttpServletRequest) request; HttpServletResponse httpResponse = (HttpServletResponse) response; Player player = sessionUtil.getUser(httpRequest); if (player == null) { sessionUtil.setLoginRedirectPath(httpRequest, httpRequest.getRequestURI()); httpResponse.sendRedirect(httpResponse.encodeRedirectURL("/login")); return; } Set<Privilege> privileges = sessionUtil.getPrivileges(httpRequest); String pathInfo = httpRequest.getRequestURI().substring(httpRequest.getContextPath().length()); for (Privilege privilege : privileges) { if (privilege.getPathPattern().matcher(pathInfo).matches()) { chain.doFilter(request, response); if (!StringUtils.isEmpty(httpRequest.getMethod()) && httpRequest.getMethod().equalsIgnoreCase("POST")) { LOG.info(String.format("AUDIT: %s executed %s %s", player, httpRequest.getMethod(), httpRequest.getRequestURI())); Enumeration<String> parameterNames = request.getParameterNames(); while (parameterNames.hasMoreElements()) { String paramName = parameterNames.nextElement(); String paramValue = request.getParameter(paramName); LOG.info(String.format("%s: %s", paramName, paramValue)); } } return; } } httpResponse.sendError(HttpStatus.SC_FORBIDDEN); } else { chain.doFilter(request, response); } }
From source file:adminServlets.AddFlowerServlet.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try {/* ww w. j av a 2 s. c om*/ FlowerService flowerService = new FlowerService(); Flower flower = new Flower(); BeanUtils.populate(flower, request.getParameterMap()); if (flowerService.addFlower(flower)) response.sendRedirect(getServletContext().getRealPath("/") + "AdminView/FlowerAddition.jsp"); } catch (IllegalAccessException ex) { Logger.getLogger(AddFlowerServlet.class.getName()).log(Level.SEVERE, null, ex); } catch (InvocationTargetException ex) { Logger.getLogger(AddFlowerServlet.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:org.iti.agrimarket.view.LoginController.java
@RequestMapping(value = "/dummylogin.htm", method = RequestMethod.GET) public String loginDummy(HttpServletRequest request, HttpServletResponse response, Model model) { User result = userService.getUserEager(1); if (result == null) { model.addAttribute("error", "Invalid Email or password!"); return "sign_in"; }//from www . j a v a2 s . c om request.getSession().setAttribute("user", result); try { response.sendRedirect(request.getContextPath() + "/index.htm"); } catch (IOException ex) { Logger.getLogger(UserController.class.getName()).log(Level.SEVERE, null, ex); } return "profile"; }
From source file:edu.ku.kuali.kra.award.web.struts.action.AwardHomeAction.java
private ActionForward redirectAwardHistoryFullViewForPopup(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response, String awardDocumentNumber, String awardNumber) throws Exception { // super.populateAwardHierarchy(form); AwardForm awardForm = (AwardForm) form; response.sendRedirect("awardHistory.do?methodToCall=openWindow&awardDocumentNumber=" + awardDocumentNumber + "&awardNumber=" + awardNumber + "&docTypeName=" + awardForm.getDocTypeName()); return null;// w w w .ja v a 2 s . c o m }
From source file:br.edu.ifpb.ads.psd.projeto.servlets.UploadImagemPerfil.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request//from w ww. j a va2s.c o m * @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 { Usuario usuario = ((Usuario) request.getSession().getAttribute("usuario")); if (usuario == null) { response.sendRedirect(""); } else { boolean isMultipart = ServletFileUpload.isMultipartContent(request); if (isMultipart) { FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); List<FileItem> items = null; try { items = (List<FileItem>) upload.parseRequest(request); } catch (FileUploadException ex) { Logger.getLogger(UploadImagemPerfil.class.getName()).log(Level.SEVERE, null, ex); } FileItem item = items.get(0); if (item != null) { String nome_arquivo = String.valueOf(new Date().getTime()) + item.getName(); String caminho = getServletContext().getRealPath("/imagens") + "\\" + usuario.getId() + "\\"; File file = new File(caminho); if (!file.exists()) { file.mkdirs(); } File uploadedFile = new File(caminho + nome_arquivo); try { item.write(uploadedFile); } catch (Exception ex) { Logger.getLogger(UploadImagemPerfil.class.getName()).log(Level.SEVERE, null, ex); } GerenciadorDeUsuario gerenciarUsuario = new GerenciadorDeUsuario(); try { gerenciarUsuario.atualizarFotoPerfil("imagens" + "/" + usuario.getId() + "/" + nome_arquivo, usuario.getId()); } catch (SQLException ex) { Logger.getLogger(UploadImagemPerfil.class.getName()).log(Level.SEVERE, null, ex); } GerenciarFotos gerenciarFotos = new GerenciarFotos(); try { gerenciarFotos.publicarFoto("imagens" + "/" + usuario.getId() + "/" + nome_arquivo, usuario); } catch (SQLException ex) { Logger.getLogger(UploadImagemPerfil.class.getName()).log(Level.SEVERE, null, ex); } try { usuario = gerenciarUsuario.getUsuario(usuario.getId()); } catch (SQLException ex) { Logger.getLogger(UploadImagemPerfil.class.getName()).log(Level.SEVERE, null, ex); } request.getSession().setAttribute("usuario", usuario); response.sendRedirect("configuracao"); } else { } } } }
From source file:org.wallride.web.support.BlogLanguageRedirectStrategy.java
@Override public void sendRedirect(HttpServletRequest request, HttpServletResponse response, String url) throws IOException { String redirectUrl = request.getContextPath() + url; BlogLanguageDataValueProcessor processor = new BlogLanguageDataValueProcessor(); redirectUrl = processor.processUrl(request, redirectUrl); redirectUrl = response.encodeRedirectURL(redirectUrl); response.sendRedirect(redirectUrl); }
From source file:com.br.ifpb.servlet.UploadImagemPerfil.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request/*from w w w. jav a 2 s . c o m*/ * @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 { Usuario usuario = ((Usuario) request.getSession().getAttribute("usuario")); if (usuario == null) { response.sendRedirect(""); } else { boolean isMultipart = ServletFileUpload.isMultipartContent(request); if (isMultipart) { FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); List<FileItem> items = null; try { items = (List<FileItem>) upload.parseRequest(request); } catch (FileUploadException ex) { Logger.getLogger(UploadImagemPerfil.class.getName()).log(Level.SEVERE, null, ex); } FileItem item = items.get(0); if (item != null) { String nome_arquivo = String.valueOf(new Date().getTime()) + item.getName(); String caminho = getServletContext().getRealPath("/imagens") + "\\" + usuario.getId() + "\\"; File file = new File(caminho); if (!file.exists()) { file.mkdirs(); } File uploadedFile = new File(caminho + nome_arquivo); try { item.write(uploadedFile); } catch (Exception ex) { Logger.getLogger(UploadImagemPerfil.class.getName()).log(Level.SEVERE, null, ex); } GerenciarUsuario gerenciarUsuario = new GerenciarUsuario(); try { gerenciarUsuario.atualizarFotoPerfil("imagens" + "/" + usuario.getId() + "/" + nome_arquivo, usuario.getId()); } catch (PersistenciaException ex) { Logger.getLogger(UploadImagemPerfil.class.getName()).log(Level.SEVERE, null, ex); } GerenciarFotos gerenciarFotos = new GerenciarFotos(); try { gerenciarFotos.publicarFoto("imagens" + "/" + usuario.getId() + "/" + nome_arquivo, Timestamp.valueOf(LocalDateTime.now()), usuario); } catch (PersistenciaException ex) { Logger.getLogger(UploadImagemPerfil.class.getName()).log(Level.SEVERE, null, ex); } try { usuario = gerenciarUsuario.getUsuario(usuario.getId()); } catch (PersistenciaException ex) { Logger.getLogger(UploadImagemPerfil.class.getName()).log(Level.SEVERE, null, ex); } request.getSession().setAttribute("usuario", usuario); response.sendRedirect("configuracao"); } else { } } } }
From source file:cn.vlabs.umt.ui.actions.UserInfoAction.java
/** * ?/* w w w . j a v a2 s.c o m*/ * */ public ActionForward save(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String trueName = CommonUtils.trim(request.getParameter("trueName")); User user = getUserService().getUserByUid(SessionUtils.getUserId(request)); user.setTrueName(trueName); getUserService().updateValueByColumn(user.getId(), "true_name", trueName); response.sendRedirect(RequestUtil.addParam(RequestUtil.getContextPath(request) + "/index.jsp", "msg", "userinfo.truename.change.success")); return null; }
From source file:org.chos.transaction.passport.controller.BusinessPassportController.java
@RequestMapping(value = "/user/business/register") @ResponseBody// w w w .j a v a2 s . c o m public Object register(HttpServletRequest request, HttpServletResponse response, Model model) throws IOException { Map<String, Object> resp = new HashMap<String, Object>(); Session session = httpContextSessionManager.getSession(request); if (session == null) { response.sendRedirect("../login.shtml?returnUrl=/business/register.shtml"); } String username = request.getParameter("username"); if (StringUtils.isBlank(username)) { resp.put("code", 1000); return resp; } String mobile = request.getParameter("mobile"); if (!StringUtils.isBlank(mobile) && !mobile.matches("1[0-9]{10}")) { resp.put("code", 1100); return resp; } String email = request.getParameter("email"); // userService. Merchant merchant = new Merchant(); merchant.setName(username); merchant.setUserId(session.getUserId()); merchant.setMobile(mobile); merchant.setCreation(new Date()); userService.createMerchant(merchant); resp.put("code", 0); return resp; }