List of usage examples for javax.servlet.http HttpServletRequest getContextPath
public String getContextPath();
From source file:org.stockwatcher.web.rss.BaseRssView.java
protected String getStockLink(HttpServletRequest request, String symbol) { StringBuilder link = new StringBuilder(request.getScheme()); link.append("://"); link.append(request.getServerName()); link.append(":"); link.append(request.getServerPort()); link.append(request.getContextPath()); link.append("/main/stocks/"); link.append(symbol);// w w w . jav a2s.c o m return link.toString(); }
From source file:com.ci6225.marketzone.servlet.seller.AddProductServlet.java
/** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse * response)// w w w .j ava 2 s. c o m */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub response.getWriter().append("Served at: ").append(request.getContextPath()); }
From source file:com.doculibre.constellio.filters.LocalRequestFilter.java
private boolean isFileRequest(ServletRequest request) { HttpServletRequest httpRequest = (HttpServletRequest) request; HttpSession httpSession = httpRequest.getSession(); ServletContext servletContext = httpSession.getServletContext(); String contextPath = httpRequest.getContextPath(); String requestURI = httpRequest.getRequestURI(); String contextRelativePath = requestURI.substring(contextPath.length()); String possibleFilePath = servletContext.getRealPath(contextRelativePath); return new File(possibleFilePath).exists(); }
From source file:de.otto.jsonhome.controller.HtmlController.java
@RequestMapping(value = "/rel/**", method = RequestMethod.GET, produces = "text/html") public ModelAndView getRelationshipType(final HttpServletRequest request) { final URI relationTypeURI = URI.create(request.getRequestURL().toString()); final Map<String, Object> model = new HashMap<String, Object>(); model.put("contextpath", request.getContextPath()); final JsonHome jsonHome = jsonHomeSource.getJsonHome(); if (jsonHome.hasResourceFor(relationTypeURI)) { final ResourceLink resourceLink = jsonHome.getResourceFor(relationTypeURI); model.put("resource", resourceLink); if (resourceLink.isDirectLink()) { return new ModelAndView("directresource", model); } else {/*from w w w . ja v a 2s . com*/ return new ModelAndView("templatedresource", model); } } else { throw new IllegalArgumentException("Unknown relation type " + relationTypeURI); } }
From source file:com.cpjit.swagger4j.support.struts2.ApiAction.java
private Properties loadSettings(HttpServletRequest request) throws IOException { Properties props = new Properties(); InputStream is = ResourceUtil.getResourceAsStream("swagger.properties"); props.load(is);//w w w . j a va 2 s.c o m String path = request.getContextPath(); String host = request.getServerName() + ":" + request.getServerPort() + path; props.setProperty("apiHost", host); String apiFile = props.getProperty("apiFile"); if (StringUtils.isBlank(apiFile)) { apiFile = DEFAULT_API_FILE; } String apiFilePath = request.getServletContext().getRealPath(apiFile); props.setProperty("apiFile", apiFilePath); if (StringUtils.isBlank(props.getProperty("devMode"))) { props.setProperty("devMode", devMode); } String suffix = props.getProperty("suffix"); if (StringUtils.isBlank(suffix)) { suffix = ""; } props.put("suffix", suffix); return props; }
From source file:com.intuit.tank.admin.LogViewer.java
public String getLogFileUrl() { String ret = null;//from w w w . j a v a 2 s . co m if (StringUtils.isNotBlank(currentLogFile)) { HttpServletRequest req = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext() .getRequest(); try { ret = getContextRoot(req.getContextPath()) + "rest" + ReportService.SERVICE_RELATIVE_PATH + "/" + URLEncoder.encode(currentLogFile, "UTF-8"); } catch (UnsupportedEncodingException e) { // never happens stupid exception } } return ret; }
From source file:ar.com.zauber.commons.spring.web.controllers.AbstractRestishController.java
/** @see AbstractController#handleRequestInternal(HttpServletRequest, * HttpServletResponse) @throws Exception on error */ public final ModelAndView handleRequestInternal(final HttpServletRequest request, final HttpServletResponse response) throws Exception { final String uri = request.getRequestURI().substring(request.getContextPath().length()); final String[] patharray = uri.split("/"); ModelAndView ret;//from w ww.j ava2 s. co m if (!uri.endsWith("/")) { ret = new ModelAndView(springWebUtil.createRedirect(uri + "/")); } else if (patharray.length == firstIndex) { ret = list(request, response); } else if (patharray.length == firstIndex + 1) { final Long id = (Long) seoStrategy.getIdFromSEOFriendly(patharray[firstIndex]); if (id == null) { throw new NoSuchEntityException(patharray[firstIndex]); } ret = entity(id, request, response); } else if (patharray.length == firstIndex + 2) { final Long id = (Long) seoStrategy.getIdFromSEOFriendly(patharray[firstIndex]); if (id == null) { throw new NoSuchEntityException(patharray[firstIndex]); } if (callEntityOnRelationship) { ret = entity(id, request, response); } final String action = patharray[firstIndex + 1]; try { final Method m = getClass().getMethod(action, long.class, HttpServletRequest.class, HttpServletResponse.class); ret = (ModelAndView) m.invoke(this, id, request, response); } catch (NoSuchMethodException e) { ret = onMethodFound(request, response); } } else { throw new IllegalArgumentException(); } return ret; }
From source file:pivotal.au.se.gemfirexdweb.controller.HistoryController.java
@RequestMapping(value = "/history", method = RequestMethod.GET) public String showHistory(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 {/*from w ww. j a va 2s . co m*/ 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 command history"); UserPref userPref = (UserPref) session.getAttribute("prefs"); String histAction = request.getParameter("histAction"); if (histAction != null) { logger.debug("histAction = " + histAction); // clear history session.setAttribute("history", new LinkedList()); model.addAttribute("historyremoved", "Succesfully cleared history list"); } LinkedList historyList = (LinkedList) session.getAttribute("history"); int maxsize = userPref.getHistorySize(); model.addAttribute("historyList", historyList.toArray()); model.addAttribute("historysize", historyList.size()); // This will resolve to /WEB-INF/jsp/history.jsp return "history"; }
From source file:com.brokenmodel.swats.RouterServlet.java
private void handleRequest(HttpServletRequest request, HttpServletResponse response, ControllerRequest.Type type) { try {/*w w w. j a va 2s . co m*/ URL rootURL = new URL(request.getScheme(), request.getServerName(), request.getServerPort(), request.getContextPath() + request.getServletPath()); String appRoot = rootURL.getFile(); String htmlRoot = request.getContextPath(); MatchedRoute matchedRoute = controllers.matchRoute(request.getPathInfo()); ControllerRequest controllerRequest = new ControllerRequest(request, response, appRoot, htmlRoot, matchedRoute.getUrlParams(), type, handleMultipart(request), getDataSource()); AbstractController controller = matchedRoute.getController(); controller.doRequest(controllerRequest); } catch (Throwable t) { log(t); try { // only will work if output stream has not been opened PrintWriter pw = new PrintWriter(response.getWriter()); pw.append("<pre>"); pw.append("We're sorry - an error has occurred:\n\n"); t.printStackTrace(pw); pw.append("</pre>"); } catch (Throwable t2) { } } }
From source file:feedme.controller.LogoutServlet.java
/** * Handles the HTTP <code>GET</code> method. * * @param request servlet request/*from w ww . jav a 2s. 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 doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); request.getSession().removeAttribute("AuthenticatUser");//remove session response.sendRedirect(request.getContextPath() + "/");//return to the main page return; }