List of usage examples for javax.servlet.http HttpServletRequest getContextPath
public String getContextPath();
From source file:info.magnolia.cms.security.auth.callback.RedirectClientCallback.java
@Override public void handle(HttpServletRequest request, HttpServletResponse response) { String target;//from www.jav a2 s. co m if (location.startsWith("/")) { target = request.getContextPath() + location; } else { target = location; } if (request.getRequestURI().equals(target)) { log.debug("Unauthorized, can't redirect further, we're already at {}", target); return; } log.debug("Unauthorized, will redirect to {}", target); try { // formats the target location with the request url, to allow passing it has a parameter, for instance. String url = request.getRequestURL().toString(); if (MgnlContext.getParameters() != null && !MgnlContext.getParameters().isEmpty()) { Set<String> keys = MgnlContext.getParameters().keySet(); String parameterString = ""; String[] values; for (String key : keys) { // we don't want to pass along the mgnlLogut parameter on a // login action if (!key.equals("mgnlLogout")) { values = MgnlContext.getParameterValues(key); for (int i = 0; i < values.length; i++) { parameterString += key + "=" + values[i] + "&"; } } } if (StringUtils.isNotBlank(parameterString)) { // cut off trailing "&" url += "?" + StringUtils.substringBeforeLast(parameterString, "&"); target += "?" + StringUtils.substringBeforeLast(parameterString, "&"); } } final String encodedUrl = URLEncoder.encode(url, "UTF-8"); final String formattedTarget = MessageFormat.format(target, encodedUrl); response.sendRedirect(formattedTarget); } catch (IOException e) { throw new RuntimeException("Can't redirect to " + target + " : " + e.getMessage(), e); } }
From source file:MyServlet.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException { //redirect the user depending on the value of the 'go' param String destination = getInitParameter("go"); String contextPath = request.getContextPath(); if (destination == null || destination.equals("")) throw new ServletException("Missing or invalid 'go' parameter in " + getClass().getName()); if (destination.equals("weather")) //ensure URL rewriting response.sendRedirect(response.encodeRedirectURL(contextPath + "/weather")); if (destination.equals("maps")) //ensure URL rewriting response.sendRedirect(response.encodeRedirectURL(contextPath + "/maps")); }
From source file:com.iwancool.dsm.admin.filter.DsmSecurityInterceptor.java
/** * controller?//from w ww. ja v a 2 s . c o m */ @SuppressWarnings("unchecked") @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { String requestPath = request.getRequestURI().substring(request.getContextPath().length()); //??? if (excludeUrls.contains(requestPath)) return true; // if (!SessionUtils.isLogin(request)) { request.setAttribute("msg", ""); request.getRequestDispatcher("/login/index").forward(request, response); return false; } List<PermissionModel> permissionList = (List<PermissionModel>) SessionUtils.getAttr(request, SessionUtils.ADMIN_PERMISSION_CACHE_KEY); return true; //return hasPermission(permissionList, requestPath); }
From source file:org.openmrs.module.tracpatienttransfer.web.controller.EPFC_OverviewController.java
@Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { ModelAndView mav = new ModelAndView(); if (Context.getAuthenticatedUser() == null) return new ModelAndView(new RedirectView(request.getContextPath() + "/login.htm")); mav.setViewName(getViewName());/*from ww w. j a v a 2 s . co m*/ Concept reasonForExingCare = Context.getConceptService() .getConcept(TransferOutInPatientConstant.REASON_PATIENT_EXITED_FROM_CARE); mav.addObject("reasons", reasonForExingCare.getAnswers()); mav.addObject("reasonForExitingCareTitle", reasonForExingCare.getDisplayString()); return mav; }
From source file:controller.ChanelManagerController.java
@RequestMapping(value = "/process", method = RequestMethod.POST) public String processChanel(HttpServletRequest req, @ModelAttribute(value = "chanel") Chanel cl, @RequestParam(value = "action") String action, ModelMap mm) { try {//from w w w .j a v a 2 s .c om String contextPath = req.getContextPath(); if (action.equalsIgnoreCase("update")) { mm.put("check", chanelModel.addOrUpdate(cl)); mm.put("alert", "Chanel Updated"); } if (action.equalsIgnoreCase("add")) { cl.setChanelId(0); mm.put("check", chanelModel.addOrUpdate(cl)); mm.put("alert", "Chanel Added"); } if (action.equalsIgnoreCase("delete")) { mm.put("check", chanelModel.delete(cl)); mm.put("alert", "Chanel Deleted"); } mm.put("link", contextPath + "/admin/chanelManager.html"); } catch (Exception ex) { ex.printStackTrace(); mm.put("err", ex.getMessage()); } return "processChanel"; }
From source file:com.flipkart.phantom.runtime.impl.jetty.filter.ServletTraceFilter.java
/** * Submits the service request endpoint data * @param request the service request// w w w .j av a2 s . com */ private void submitEndpoint(HttpServletRequest request) { if (!endPointSubmitter.endPointSubmitted()) { String contextPath = request.getContextPath(); String localAddr = request.getLocalAddr(); int localPort = request.getLocalPort(); endPointSubmitter.submit(localAddr, localPort, contextPath); LOGGER.debug("Setting endpoint: addr: {}, port: {}, contextpath: " + contextPath, localAddr, localPort); } }
From source file:com.camel.framework.tag.StaticTag.java
@Override public int doStartTag() throws JspException { this.pageContext.getServletConfig(); // jspJspWriter JspWriter out = this.pageContext.getOut(); // environmentConfig.xml?????value String resourcesUrl = null;/*from ww w . j a v a 2s.c o m*/ if (null != ConfigParamMap.getConfigParamMap()) { ConfigParamMap.getValue(IEnvironmentConfigBasic.RESOURCES_URL); } // ?null??URL if (null == resourcesUrl) { HttpServletRequest request = (HttpServletRequest) this.pageContext.getRequest(); resourcesUrl = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath(); } if (StringUtils.isNotBlank(resourcesUrl)) { try { // ?resourcesUrl????? out.print(resourcesUrl); } catch (IOException e) { logger.error("Could not print out value '" + resourcesUrl, e); } } else { logger.error("resourcesUrl is null,so static tag is invalid"); } return SKIP_BODY; }
From source file:cz.muni.pa165.carparkapp.configuration.AuthenticationHandler.java
@Override public void onAuthenticationSuccess(HttpServletRequest hsr, HttpServletResponse hsr1, Authentication a) throws IOException, ServletException { Set<String> roles = AuthorityUtils.authorityListToSet(a.getAuthorities()); if (roles.contains("ROLE_USER")) { hsr1.sendRedirect(hsr.getContextPath() + "/"); }/* w w w .j a v a 2 s . co m*/ if (roles.contains("ROLE_ADMIN")) { hsr1.sendRedirect(hsr.getContextPath() + "/admin/"); } }
From source file:sample.mvc.ExpliotDemoController.java
@RequestMapping(value = "/csrf/messages/", method = RequestMethod.POST) public void exploit(HttpServletRequest request, HttpServletResponse response) throws Exception { Message messageToSave = messageParser.parse(request.getInputStream()); messageRepository.save(messageToSave); response.sendRedirect(request.getContextPath()); }
From source file:edu.cornell.mannlib.vitro.webapp.controller.authenticate.BaseLoginServlet.java
/** * If we don't have a referrer, send them to the home page. *///w ww . j a v a2 s . co m protected String figureHomePageUrl(HttpServletRequest req) { StringBuffer url = req.getRequestURL(); String uri = req.getRequestURI(); int authLength = url.length() - uri.length(); String auth = url.substring(0, authLength); return auth + req.getContextPath(); }