List of usage examples for javax.servlet.http HttpServletRequest getContextPath
public String getContextPath();
From source file:controller.OrderProductController.java
@RequestMapping(value = "/process", method = RequestMethod.POST) public String processOrderProduct(ModelMap mm, @ModelAttribute Requirement req, HttpServletRequest request, @RequestParam String seri) { try {//from w w w. java 2 s .co m mm.put("check", rqModel.updateSerial(req.getId(), seri)); mm.put("alert", "Updated"); mm.put("link", request.getContextPath() + "/distributor/orderProduct.html"); } catch (Exception ex) { mm.put("err", ex.getMessage()); } return "processOrderProduct"; }
From source file:com.asociate.managedbean.DatosSesion.java
/** * */// ww w. j a v a2 s .c om public void logout() { FacesContext context = FacesContext.getCurrentInstance(); ExternalContext externalContext = context.getExternalContext(); Object session = externalContext.getSession(false); HttpSession httpSession = (HttpSession) session; httpSession.invalidate(); HttpServletRequest origRequest = (HttpServletRequest) context.getExternalContext().getRequest(); String contextPath = origRequest.getContextPath(); try { FacesContext.getCurrentInstance().getExternalContext().redirect(contextPath + "/faces/index.xhtml"); } catch (IOException e) { e.printStackTrace(); } }
From source file:org.jasig.portlet.notice.controller.rest.JPANotificationRESTController.java
/** * Build the URL for a specific notification. * * @param request the Http request/* w w w .j av a 2 s.c om*/ * @param id the notification id * @return the URL to hit that specific id */ private String getSingleNotificationRESTUrl(HttpServletRequest request, long id) { String path = request.getContextPath() + API_ROOT + REQUEST_ROOT + id; try { URL url = new URL(request.getScheme(), request.getServerName(), request.getServerPort(), path); return url.toExternalForm(); } catch (MalformedURLException e) { // if it fails, just return a relative path. Not ideal, but better than nothing... log.warn("Error building Location header", e); return path; } }
From source file:br.com.gerenciapessoal.security.JsfAccessDeniedHandler.java
@Override public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException { String redirectUrl = calculateRedirectUrl(request.getContextPath(), loginPath); redirectUrl = response.encodeRedirectURL(redirectUrl); //we should redirect using ajax response if the case warrants boolean ajaxRedirect = request.getHeader("faces-request") != null && request.getHeader("faces-request").toLowerCase().contains("ajax"); if (ajaxRedirect) { //javax.faces.context.FacesContext ctxt = javax.faces.context.FacesContext.getCurrentInstance(); //ctxt.getExternalContext().redirect(redirectUrl); String ajaxRedirectXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<partial-response><redirect url=\"" + redirectUrl + "\"></redirect></partial-response>"; response.setContentType("text/xml"); response.getWriter().write(ajaxRedirectXml); } else {/*from w ww . jav a 2 s .c o m*/ response.sendRedirect(redirectUrl); } }
From source file:org.uoiu.platform.web.IndexController.java
@RequestMapping(value = "/index", method = RequestMethod.GET) public ModelAndView index(@RequestParam(value = "username", required = false) String username, @RequestParam(value = "password", required = false) String password, @RequestParam(value = "mainAppName", required = false) String mainAppName, Model model, HttpServletRequest request) { System.out.println(username + ":" + password); ModelAndView mv = new ModelAndView("index"); mv.addObject("resourceUrl", "/resources-" + env.getProperty("application.version")); mv.addObject("ctx", request.getContextPath()); mv.addObject("mainAppName", StringUtils.isEmpty(mainAppName) ? "uoiu/platform/PlatformApp" : mainAppName); return mv;// ww w . j ava2 s. c o m }
From source file:gov.nih.nci.calims2.taglib.form.ButtonTag.java
private void addUrl(Tag tag) throws JspTagException { if (url != null) { HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); String fullUrl = (url.startsWith("/")) ? request.getContextPath() + url : url; Tag scriptTag = tag.addChild(new CompositeTag(HtmlElement.SCRIPT)); scriptTag.addAttribute("args", "evt"); scriptTag.addAttribute("event", "onClick"); scriptTag.addAttribute("type", "dojo/method"); FormTag formTag = FormTag.getFormTagLocator().getTag(pageContext, this); String setAction = "dojo.byId(\"" + formTag.getId() + "\").action = \"" + fullUrl + "\";\ndijit.byId(\"" + formTag.getId() + "\").validateFlag = " + validate + ";"; ContentTag contentTag = scriptTag.addChild(new ContentTag(setAction)); contentTag.setContentType(ContentType.TEXT); }/*from w ww .ja v a 2s . c o m*/ }
From source file:com.pearson.pdn.demos.chainoflearning.RegisterServlet.java
@Override protected void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { String email = req.getParameter("email"); if (email == null || !email.matches(EMAIL_PATTERN)) { res.sendRedirect(req.getContextPath() + "/register.jsp"); return;/* www . j a v a 2 s . c o m*/ } HttpSession session = req.getSession(true); // TODO - do this better. actually persist it... String verifyCode = Base64.encodeBase64String(String.valueOf(System.currentTimeMillis()).getBytes()); session.setAttribute("auth", Base64.encodeBase64String((email + ":" + verifyCode).getBytes())); // TODO - actually send an email String linkParams = "?e=" + email + "&v=" + verifyCode; String emailContent = "Hello " + email + ",<br /><br /><a id=\"email-link\" href=\"./oauth2" + linkParams + "\">Link</a> your calendar with ChainOfLearning. <br/ > <br /> Thanks!"; req.setAttribute("emailContent", emailContent); req.setAttribute("email", email); req.getRequestDispatcher("/activation.jsp").forward(req, res); }
From source file:controller.DistributorManagerController.java
@RequestMapping(value = "/process", method = RequestMethod.POST) public String processDistributor(HttpServletRequest req, @RequestParam(value = "action") String action, @ModelAttribute(value = "distributor") Distributor dis, ModelMap mm) { try {/*from w ww.jav a 2 s .c o m*/ String contextPath = req.getContextPath(); if (action.equalsIgnoreCase("update")) { mm.put("check", disModel.addOrUpdate(dis)); mm.put("alert", "Distributor Updated"); } if (action.equalsIgnoreCase("Add")) { dis.setDistributorId(0); mm.put("check", disModel.addOrUpdate(dis)); mm.put("alert", "Distributor Added"); } if (action.equalsIgnoreCase("delete")) { mm.put("check", disModel.delete(dis)); mm.put("alert", "Distributor Deleted"); } mm.put("link", contextPath + "/admin/distributorManager.html"); } catch (Exception ex) { ex.printStackTrace(); mm.put("err", ex.getMessage()); } return "processDistributor"; }
From source file:org.openmrs.module.tracdataquality.web.controller.DataQualityAlertsController.java
/** * defines criterias, the number of the patients in each criteria and sets them on views as * alerts/*from w ww. ja va2 s . c o m*/ * * @see org.springframework.web.servlet.mvc.AbstractController#handleRequestInternal(javax.servlet.http.HttpServletRequest, * javax.servlet.http.HttpServletResponse) */ @Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { //check if the user is logged in if (Context.getAuthenticatedUser() == null) return new ModelAndView(new RedirectView(request.getContextPath() + "/login.htm")); ModelAndView mav = new ModelAndView(); mav.setViewName(getViewName()); //start looking for data quality by checking each indicator Map<String, Integer> patientNumbers = new HashMap<String, Integer>(); try { for (String key : TracDataQualityUtil.getCriteriaKeys()) { DataQualityByCheckTypeController checkingDataQuality = new DataQualityByCheckTypeController(); patientNumbers.put(key, checkingDataQuality.checkTypeController(key, "").size()); } mav.addObject("patientNumbers", patientNumbers); } catch (Exception e) { log.error(">>>>>TRAC>>DATA>>QUALITY>> " + e.getMessage()); e.printStackTrace(); } return mav; }
From source file:gov.nih.nci.ncicb.cadsr.common.jsp.tag.handler.SecureIconDisplay.java
private String getHrefUrl(HttpServletRequest req, Form form) throws JspException { req.getContextPath(); StringBuffer sb = new StringBuffer(req.getContextPath() + activeUrl); if (activeUrl != null && paramId != null && paramProperty != null) { if (activeUrl.indexOf("=") != -1) if (!activeUrl.endsWith("&")) sb.append("&"); sb.append(paramId + "=" + getParamValue(form, paramProperty)); }//from ww w .j ava2 s .co m return sb.toString(); }