List of usage examples for javax.servlet.http HttpServletRequest removeAttribute
public void removeAttribute(String name);
From source file:com.opencnc.controllers.ElementoGraficoController.java
/** * ***************************************************************************** * Borra los elementos graficos del modelo. * ***************************************************************************** * Metodo sin funcion.//from w w w .j a v a 2 s.c o m * ***************************************************************************** * @param id * @param request * @param response * @return * @throws Exception */ @RequestMapping("/elemento/borrar/{id}") public ModelAndView borrar(@PathVariable Integer id, HttpServletRequest request, HttpServletResponse response) throws Exception { HttpSession sess = request.getSession(); if (sess != null) { Session s = HibernateUtil.getSessionFactory().openSession(); ElementoGrafico e = (ElementoGrafico) s.get(ElementoGrafico.class, id); Transaction t = s.beginTransaction(); s.delete(e); t.commit(); return lista(request, response); } else { request.removeAttribute("usuario"); return new ModelAndView("redirect:/usuario/login.htm"); } }
From source file:com.redhat.rhn.frontend.struts.StrutsDelegate.java
private void bindMessage(HttpServletRequest request, String key, List<? extends ValidationMessage> messages, ActionMessages actMsgs) {/* w w w .j a v a 2 s . com*/ if (!messages.isEmpty()) { for (ValidationMessage msg : messages) { actMsgs.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(msg.getKey(), msg.getValues())); } ActionMessages requestMsg = (ActionMessages) request.getAttribute(key); if (requestMsg == null) { requestMsg = new ActionMessages(); } requestMsg.add(actMsgs); if (requestMsg.isEmpty()) { request.removeAttribute(key); } else { request.setAttribute(key, requestMsg); request.getSession().setAttribute(key, requestMsg); } } }
From source file:org.apache.struts.scaffold.RemoveAttributeAction.java
/** * // :FIXME: Needs to be tested.<p> * Attempt to remove an attribute from a servlet context. * Find "success" if attribute exists, or "failure" if not. * * The servlet context and attributes are specified as the * parameters property, seperated by semi-colons * [parameter="application;HOURS].// w ww . j a va 2 s . co m * non-error state. * * To indicate that all scopes are to be checked, * specify an asterisk instead of the scope name * [parameter="*;HOURS]. The attribute will be removed * from <b>only</b> the first context found. * * If both parameters are not given, an error is set. * * @param mapping The ActionMapping used to select this instance * @param form The optional ActionForm bean for this request * @param request The HTTP request we are processing * @param response The response we are creating * @todo Add support for multiple attributes * @fixme Needs to be tested. */ protected ActionForward findSuccess(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { String[] parameters = tokenize(mapping.getParameter()); // If not 2+ parameters, bail if (2 > parameters.length) { ActionErrors errors = new ActionErrors(); errors.add(ActionErrors.GLOBAL_ERROR, new ActionError(Tokens.PROCESS_MISSING_PARAMETER)); saveErrors(request, errors); return mapping.findForward(Tokens.FAILURE); } String scope = parameters[0]; Object bean = null; String name = parameters[1]; // :TODO: Add support for multiple attributes boolean any = ("*".equals(scope)); if (any) { bean = request.getAttribute(name); if (null != bean) request.removeAttribute(name); if (null == bean) { bean = request.getSession().getAttribute(name); if (null != bean) request.getSession().removeAttribute(name); } if (null == bean) { bean = servlet.getServletContext().getAttribute(name); if (null != bean) servlet.getServletContext().removeAttribute(name); } } // end any else { if (Tokens.REQUEST.equals(scope)) { bean = request.getAttribute(name); request.removeAttribute(name); } if (Tokens.SESSION.equals(scope)) { bean = request.getSession().getAttribute(name); request.getSession().removeAttribute(name); } if (Tokens.APPLICATION.equals(scope)) { bean = servlet.getServletContext().getAttribute(name); servlet.getServletContext().removeAttribute(name); } } // end !any if (null == bean) { return mapping.findForward(Tokens.FAILURE); } return mapping.findForward(Tokens.SUCCESS); }
From source file:edu.morgan.server.UploadFile.java
@Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException { // Check that we have a file upload request RequestDispatcher rd;/*from www . j a va 2 s . c o m*/ response.setContentType("text/html"); isMultipart = ServletFileUpload.isMultipartContent(request); if (!isMultipart) { rd = request.getRequestDispatcher("fail.jsp"); rd.forward(request, response); } try { ServletFileUpload upload = new ServletFileUpload(); response.setContentType("text/plain"); FileItemIterator iterator = upload.getItemIterator(request); while (iterator.hasNext()) { FileItemStream item = iterator.next(); InputStream stream = item.openStream(); this.read(stream); } request.removeAttribute("incompleteStudents"); request.setAttribute("incompleteStudents", studentList); rd = request.getRequestDispatcher("Success"); rd.forward(request, response); } catch (Exception ex) { throw new ServletException(ex); } }
From source file:net.shopxx.interceptor.LogInterceptor.java
@SuppressWarnings("unchecked") @Override//from ww w.j ava 2 s . c o m public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { //List<LogConfig> logConfigs = logConfigService.getAll(); //?????? List<LogConfig> logConfigs = logConfigService.findAll(); if (logConfigs != null) { String path = request.getServletPath(); for (LogConfig logConfig : logConfigs) { if (antPathMatcher.match(logConfig.getUrlPattern(), path)) { String username = adminService.getCurrentUsername(); String operation = logConfig.getOperation(); String operator = username; String content = (String) request.getAttribute(Log.LOG_CONTENT_ATTRIBUTE_NAME); String ip = request.getRemoteAddr(); request.removeAttribute(Log.LOG_CONTENT_ATTRIBUTE_NAME); StringBuffer parameter = new StringBuffer(); Map<String, String[]> parameterMap = request.getParameterMap(); if (parameterMap != null) { for (Entry<String, String[]> entry : parameterMap.entrySet()) { String parameterName = entry.getKey(); if (!ArrayUtils.contains(ignoreParameters, parameterName)) { String[] parameterValues = entry.getValue(); if (parameterValues != null) { for (String parameterValue : parameterValues) { parameter.append(parameterName + " = " + parameterValue + "\n"); } } } } } Log log = new Log(); log.setOperation(operation); log.setOperator(operator); log.setContent(content); log.setParameter(parameter.toString()); log.setIp(ip); logService.save(log); break; } } } }
From source file:org.springframework.boot.web.servlet.support.ErrorPageFilter.java
private void forwardToErrorPage(String path, HttpServletRequest request, HttpServletResponse response, Throwable ex) throws ServletException, IOException { if (logger.isErrorEnabled()) { String message = "Forwarding to error page from request " + getDescription(request) + " due to exception [" + ex.getMessage() + "]"; logger.error(message, ex);/*from w ww .j av a 2 s . c o m*/ } setErrorAttributes(request, 500, ex.getMessage()); request.setAttribute(ERROR_EXCEPTION, ex); request.setAttribute(ERROR_EXCEPTION_TYPE, ex.getClass()); response.reset(); response.setStatus(500); request.getRequestDispatcher(path).forward(request, response); request.removeAttribute(ERROR_EXCEPTION); request.removeAttribute(ERROR_EXCEPTION_TYPE); }
From source file:com.glaf.oa.assessquestion.web.springmvc.AssessquestionController.java
@RequestMapping("/edit") public ModelAndView edit(HttpServletRequest request, ModelMap modelMap) { RequestUtils.setRequestParameterToAttribute(request); request.removeAttribute("canSubmit"); Assessquestion assessquestion = assessquestionService .getAssessquestion(RequestUtils.getLong(request, "qustionid")); List<BaseDataInfo> isValidList = AQUtils.getBaseInfoByCode("ASSESS_ISVALID"); Map<String, BaseDataInfo> validMap = AQUtils.baseList2MapByCode(isValidList); if (assessquestion != null) { assessquestion.setIseffectiveText(validMap.get(assessquestion.getIseffective() + "").getName()); modelMap.put("isValidList", isValidList); modelMap.put("assessquestion", assessquestion); }/*from w ww. j av a 2s .co m*/ boolean canUpdate = false; String x_method = request.getParameter("x_method"); if (StringUtils.equals(x_method, "submit")) { } if (StringUtils.containsIgnoreCase(x_method, "update")) { if (assessquestion != null) { canUpdate = true; } } request.setAttribute("canUpdate", canUpdate); String view = request.getParameter("view"); if (StringUtils.isNotEmpty(view)) { return new ModelAndView(view, modelMap); } String x_view = ViewProperties.getString("assessquestion.edit"); if (StringUtils.isNotEmpty(x_view)) { return new ModelAndView(x_view, modelMap); } return new ModelAndView("/oa/assessquestion/assessquestionEdit", modelMap); }
From source file:com.glaf.cms.info.web.springmvc.PublicInfoMgmtController.java
@RequestMapping("/edit") public ModelAndView edit(HttpServletRequest request, ModelMap modelMap) { User user = RequestUtils.getUser(request); String actorId = user.getActorId(); RequestUtils.setRequestParameterToAttribute(request); request.removeAttribute("canSubmit"); String serviceKey = request.getParameter("serviceKey"); Long nodeId = RequestUtils.getLong(request, "nodeId"); PublicInfo publicInfo = publicInfoService.getPublicInfo(request.getParameter("id")); if (publicInfo != null) { request.setAttribute("publicInfo", publicInfo); JSONObject rowJSON = publicInfo.toJsonObject(); request.setAttribute("x_json", rowJSON.toJSONString()); serviceKey = publicInfo.getServiceKey(); nodeId = publicInfo.getNodeId(); }/*from w w w. j ava2s . c o m*/ if (StringUtils.isNotEmpty(serviceKey)) { TreeModel treeModel = treeModelService.getTreeModelByCode(serviceKey); request.setAttribute("treeModel", treeModel); } if (nodeId > 0) { TreeModel treeModel = treeModelService.getTreeModel(nodeId); request.setAttribute("treeModel", treeModel); } boolean canUpdate = false; boolean canSubmit = false; String x_method = request.getParameter("x_method"); if (StringUtils.equals(x_method, "submit")) { if (publicInfo != null && publicInfo.getProcessInstanceId() != null) { ProcessContainer container = ProcessContainer.getContainer(); Collection<Long> processInstanceIds = container.getRunningProcessInstanceIds(actorId); if (processInstanceIds.contains(publicInfo.getProcessInstanceId())) { canSubmit = true; } if (publicInfo.getStatus() == 0 || publicInfo.getStatus() == -1) { canUpdate = true; } TaskItem taskItem = container.getMinTaskItem(actorId, publicInfo.getProcessInstanceId()); if (taskItem != null) { request.setAttribute("taskItem", taskItem); } List<ActivityInstance> stepInstances = container .getActivityInstances(publicInfo.getProcessInstanceId()); request.setAttribute("stepInstances", stepInstances); request.setAttribute("stateInstances", stepInstances); } else { canSubmit = true; canUpdate = true; } } if (StringUtils.containsIgnoreCase(x_method, "update")) { if (publicInfo != null) { if (publicInfo.getStatus() == 0 || publicInfo.getStatus() == -1) { canUpdate = true; } } } if (publicInfo != null) { List<DataFile> dataFiles = blobService.getBlobList(publicInfo.getId()); request.setAttribute("dataFiles", dataFiles); } request.setAttribute("canSubmit", canSubmit); request.setAttribute("canUpdate", canUpdate); String view = request.getParameter("view"); if (StringUtils.isNotEmpty(view)) { return new ModelAndView(view, modelMap); } String x_view = ViewProperties.getString("publicInfo.edit"); if (StringUtils.isNotEmpty(x_view)) { return new ModelAndView(x_view, modelMap); } return new ModelAndView("/cms/info/edit", modelMap); }
From source file:com.opencnc.controllers.UsuarioController.java
/** * ***************************************************************************** * Valida los datos de e-mail y contrasea, crea la variable de sesion. * ***************************************************************************** * @param usuario// www . ja v a 2 s . c o m * @param request * @param response * @return * @throws IOException */ @RequestMapping("/usuario/iniciarSesion") public ModelAndView iniciarSesion(@ModelAttribute Usuario usuario, HttpServletRequest request, HttpServletResponse response) throws IOException { ModelAndView m = new ModelAndView(); Session s = HibernateUtil.getSessionFactory().openSession(); EncryptController enc = new EncryptController(); Criteria c = s.createCriteria(Usuario.class); c.add(Restrictions.eq("email", usuario.getEmail())); //encripta la clave y la compara con la de la base de datos. c.add(Restrictions.eq("clave", enc.encriptado(usuario.getClave()))); //c.add(Restrictions.eq("clave", usuario.getClave())); List<Usuario> l = c.list(); if (l.isEmpty()) { m.addObject("errorId", null); request.removeAttribute("usuario"); try { return login(); //return m; } catch (Exception ex) { java.util.logging.Logger.getLogger(UsuarioController.class.getName()).log(Level.SEVERE, null, ex); } } else { Usuario ul = l.get(0); HttpSession ses = request.getSession(); ses.setAttribute("usuario", ul); request.setAttribute("usuario", ul); try { //return lista(request); //return new ModelAndView("redirect:/modelo/crearModelo.htm"); //return crearModelo(request); return ModeloController.crearModelo(request, response); } catch (Exception ex) { java.util.logging.Logger.getLogger(UsuarioController.class.getName()).log(Level.SEVERE, null, ex); } } return null; }
From source file:com.glaf.oa.borrow.web.springmvc.BorrowController.java
@RequestMapping("/edit") public ModelAndView edit(HttpServletRequest request, ModelMap modelMap) { RequestUtils.setRequestParameterToAttribute(request); request.removeAttribute("canSubmit"); Borrow borrow = borrowService.getBorrow(RequestUtils.getLong(request, "borrowid")); if (borrow != null) { request.setAttribute("borrow", borrow); JSONObject rowJSON = borrow.toJsonObject(); request.setAttribute("x_json", rowJSON.toJSONString()); }//from w w w. j a va2 s.co m boolean canUpdate = false; String x_method = request.getParameter("x_method"); if (StringUtils.equals(x_method, "submit")) { } if (StringUtils.containsIgnoreCase(x_method, "update")) { if (borrow != null) { if (borrow.getStatus() == 0 || borrow.getStatus() == -1) { canUpdate = true; } } } request.setAttribute("canUpdate", canUpdate); String view = request.getParameter("view"); if (StringUtils.isNotEmpty(view)) { return new ModelAndView(view, modelMap); } String x_view = ViewProperties.getString("borrow.edit"); if (StringUtils.isNotEmpty(x_view)) { return new ModelAndView(x_view, modelMap); } return new ModelAndView("/oa/borrow/edit", modelMap); }