List of usage examples for javax.servlet.http HttpServletResponse encodeUrl
@Deprecated
public String encodeUrl(String url);
From source file:CounterRewrite.java
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { HttpSession session = req.getSession(true); resp.setContentType("text/html"); PrintWriter out = resp.getWriter(); int count = 1; Integer i = (Integer) session.getAttribute(COUNTER_KEY); if (i != null) { count = i.intValue() + 1;//from w ww. j a v a 2 s.com } session.setAttribute(COUNTER_KEY, new Integer(count)); out.println("<html>"); out.println("<head>"); out.println("<title>Session Counter</title>"); out.println("</head>"); out.println("<body>"); out.println("Your session ID is <b>" + session.getId()); out.println("</b> and you have hit this page <b>" + count + "</b> time(s) during this browser session"); String url = req.getRequestURI(); out.println("<form method=GET action=\"" + resp.encodeURL(url) + "\">"); out.println("<input type=submit " + "value=\"Hit page again\">"); out.println("</form>"); out.println("</body>"); out.println("</html>"); out.flush(); }
From source file:org.plutext.htmleditor.EditorImage.java
/** * CK3 specific image upload/* w ww.j a v a2s . c o m*/ * * @param request * @param CKEditorFuncNum * @param imageInputStream * @param imageFileDetail * @return * @throws Docx4JException * @throws IOException */ @POST @Consumes("multipart/form-data") @Produces("text/html") public Response ck3ImageUpload( // @Context ServletContext servletContext, @Context HttpServletRequest request, @Context HttpServletResponse response, @QueryParam("CKEditorFuncNum") String CKEditorFuncNum, @FormDataParam("upload") InputStream imageInputStream, @FormDataParam("upload") FormDataContentDisposition imageFileDetail) throws Docx4JException, IOException { // <input id="cke_131_fileInput_input" aria-labelledby="cke_130_label" type="file" name="upload" size="38"> try { HttpSession session = request.getSession(false); String name = "uploaded_" + this.getFileName(imageFileDetail.getFileName()); SessionImageHandler.getImageMap(session).put(name, IOUtils.toByteArray(imageInputStream)); jul.info("stored " + name); String url = response.encodeURL(Editor.getContextPath() + "/services/image/" + name); String html = "<html><body><script type=\"text/javascript\">" + "window.parent.CKEDITOR.tools.callFunction(" + CKEditorFuncNum + ", \"" + url + "\", \"\" );window.close();" + "</script></body></html>"; return Response.ok(html).build(); } catch (Exception e) { e.printStackTrace(); System.out.println(e.getMessage()); String html = "<html><body><script type=\"text/javascript\">" + "window.close();window.opener.CKEDITOR.tools.callFunction(" + CKEditorFuncNum + "," + " \"\", \"An error occured\" );" + "</script></body></html>"; return Response.ok(html).build(); // TODO not ok // throw new WebApplicationException( // new Docx4JException(e.getMessage(), e), // Status.INTERNAL_SERVER_ERROR); } }
From source file:org.seasar.s2click.control.S2ClickForm.java
@Override public String getActionURL() { HttpServletRequest request = getContext().getRequest(); HttpServletResponse response = getContext().getResponse(); String requestURI = request.getRequestURI(); // JSP??/* w ww. j ava2 s. c om*/ if (requestURI.endsWith(".jsp")) { // TODO c:import?????????? String forwardURI = (String) request.getAttribute("javax.servlet.forward.request_uri"); if (StringUtils.isNotEmpty(forwardURI)) { requestURI = forwardURI; } else { requestURI = requestURI.replaceFirst("\\.jsp$", ".htm"); } } return response.encodeURL(requestURI); }
From source file:net.sourceforge.hunterj.javadocViewer.JavadocViewerServlet.java
/** * // ww w .j a va 2 s .c o m * @param request * @param response * @throws IOException * @throws ServletException */ private void dispatchToView(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(); request.setAttribute(JVConst.DOCHOME_ATTR.value, session.getAttribute(JVConst.DOCHOME_ATTR.value)); String docHomeOpts = (String) request.getSession().getAttribute(JVConst.DOCHOME_OPTS.value); if (docHomeOpts == null) { docHomeOpts = this.getJavadocHomeOpts(Paths.get(this.saveFilePathStr)); session.setAttribute(JVConst.DOCHOME_OPTS.value, docHomeOpts); } request.setAttribute(JVConst.DOCHOME_OPTS.value, docHomeOpts); RequestDispatcher dispatch = request.getRequestDispatcher(response.encodeURL(JVConst.MAIN_JSP.value)); dispatch.forward(request, response); }
From source file:org.jahia.bin.JahiaAdministration.java
/** * Returns a relative qualified request URL , i.e /JahiaAdministration. * * @param request//from w ww . j a v a 2 s . c o m */ private String getServletURI(HttpServletRequest request, HttpServletResponse response) { if (request == null) return ""; String pathInfo = request.getPathInfo(); String tempServletURI; if (pathInfo == null) { tempServletURI = response.encodeURL(request.getRequestURI()); } else { tempServletURI = response .encodeURL(request.getRequestURI().substring(0, request.getRequestURI().indexOf(pathInfo))); } return tempServletURI; }
From source file:ErrorGen.java
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException { //check the servlet exception Throwable throwable = (Throwable) request.getAttribute("javax.servlet.error.exception"); String servletName = (String) request.getAttribute("javax.servlet.error.servlet_name"); if (servletName == null) servletName = "Unknown"; String requestUri = (String) request.getAttribute("javax.servlet.error.request_uri"); if (requestUri == null) requestUri = "Unknown"; response.setContentType("text/html"); java.io.PrintWriter out = response.getWriter(); out.println("<html>"); out.println("<head>"); out.println("<title>Error page</title>"); out.println("</head>"); out.println("<body>"); if (throwable == null) { out.println("<h2>The error information is not available</h2>"); out.println("Please return to the <a href=\"" + response.encodeURL("http://www.java2s.com") + "\">home page</a>"); } else {/*from w ww . j a v a2 s .c o m*/ out.println("<h2>Here is the error information</h2>"); out.println("The servlet name associated with throwing the exception: " + servletName + "<br><br>"); out.println("The type of exception: " + throwable.getClass().getName() + "<br><br>"); out.println("The request URI: " + requestUri + "<br><br>"); out.println("The exception message: " + throwable.getMessage()); } out.println("</body>"); out.println("</html>"); out.close(); }
From source file:org.josso.agent.http.HttpSSOAgent.java
public String buildPostAuthUrl(HttpServletResponse hres, String requestURI, String postAuthURI) { // TODO : Is there a better way to do this ? String encURL = requestURI.replaceAll("&", "%26").replaceAll("\\?", "%3F"); return hres.encodeRedirectURL(postAuthURI + "?josso_original_resource=" + hres.encodeURL(encURL)); }
From source file:org.seasar.struts.taglib.S2FormTag.java
protected void renderAction(StringBuilder results) { HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); HttpServletResponse response = (HttpServletResponse) pageContext.getResponse(); results.append(" action=\""); String contextPath = request.getContextPath(); StringBuffer value = new StringBuffer(); if (contextPath.length() > 1) { value.append(contextPath);/* w w w. j ava 2 s . c o m*/ } value.append(action); results.append(response.encodeURL(value.toString())); results.append("\""); }
From source file:org.unitime.timetable.filter.PageAccessFilter.java
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { try {//from w ww . j a v a2s .c o m long t0 = System.currentTimeMillis(); UserContext user = getUser(); if (user != null) ApplicationProperties.setSessionId(user.getCurrentAcademicSessionId()); if (request instanceof HttpServletRequest) { HttpServletRequest r = (HttpServletRequest) request; if (r.getRequestURI().endsWith(".do")) { HttpServletResponse x = (HttpServletResponse) response; String def = r.getRequestURI().substring(r.getContextPath().length()); try { if (iPath2Tile.containsKey(def)) { String tile = iPath2Tile.get(def); ComponentDefinition c = TilesUtil.getDefinition(tile, request, iContext); HttpSession s = r.getSession(); if (c != null && "true".equals(c.getAttribute("checkLogin"))) { if (user == null) { sLog.warn("Page " + r.getRequestURI() + " denied: user not logged in"); if (s.isNew()) x.sendRedirect(x.encodeURL(r.getContextPath() + "/loginRequired.do?message=Your+timetabling+session+has+expired.+Please+log+in+again.")); else x.sendRedirect(x.encodeURL(r.getContextPath() + "/loginRequired.do?message=Login+is+required+to+use+timetabling+application.")); return; } } if (c != null && "true".equals(c.getAttribute("checkRole"))) { if (user == null || user.getCurrentAuthority() == null || !user.getCurrentAuthority().hasRight(Right.HasRole)) { sLog.warn("Page " + r.getRequestURI() + " denined: no role"); x.sendRedirect(x.encodeURL(r.getContextPath() + "/loginRequired.do?message=Insufficient+user+privileges.")); return; } } if (c != null && "true".equals(c.getAttribute("checkAdmin"))) { if (user == null || user.getCurrentAuthority() == null || !user.getCurrentAuthority().hasRight(Right.IsAdmin)) { sLog.warn("Page " + r.getRequestURI() + " denied: user not admin"); x.sendRedirect(x.encodeURL(r.getContextPath() + "/loginRequired.do?message=Insufficient+user+privileges.")); return; } } /* if (c!=null && "true".equals(c.getAttribute("checkAccessLevel"))) { String appAccess = (String) s.getAttribute(Constants.SESSION_APP_ACCESS_LEVEL); if (appAccess!=null && !"true".equalsIgnoreCase(appAccess)) { sLog.warn("Page "+r.getRequestURI()+" denied: application access disabled"); x.sendRedirect(x.encodeURL(r.getContextPath()+"/loginRequired.do?message=The+application+is+temporarily+unavailable.+Please+try+again+after+some+time.")); return; } } */ } } catch (Exception e) { sLog.warn("Unable to check page access for " + r.getRequestURI() + ", reason: " + e.getMessage(), e); } } } // Process request Throwable exception = null; try { chain.doFilter(request, response); } catch (Throwable t) { exception = t; } long t1 = System.currentTimeMillis(); if (request instanceof HttpServletRequest && ((t1 - t0) > debugTime || exception != null)) { HttpServletRequest r = (HttpServletRequest) request; String message = "Page " + r.getRequestURI() + " took " + sDF.format((t1 - t0) / 1000.0) + " s."; if (exception != null) { message = exception + " seen on page " + r.getRequestURI() + " (page took " + sDF.format((t1 - t0) / 1000.0) + " s)."; } if (exception != null || (t1 - t0) > dumpTime) { UserContext u = null; try { u = getUser(); } catch (IllegalStateException e) { } if (u == null) { message += "\n User: no user"; } else { message += "\n User: " + u.getUsername() + (u.getCurrentAuthority() != null ? " (" + u.getCurrentAuthority() + ")" : ""); } message += "\n Request parameters:"; for (Enumeration e = r.getParameterNames(); e.hasMoreElements();) { String n = (String) e.nextElement(); if ("password".equals(n)) continue; message += "\n " + n + "=" + r.getParameter(n); } try { if (dumpSessionAttribues && r.getSession() != null) { message += "\n Session attributes:"; for (Enumeration e = r.getSession().getAttributeNames(); e.hasMoreElements();) { String n = (String) e.nextElement(); message += "\n " + n + "=" + r.getSession().getAttribute(n); } } } catch (IllegalStateException e) { message += "\n INVALID SESSION"; } } else { UserContext u = getUser(); if (u == null) { message += " (User: no user)"; } else { message += " (User: " + u.getUsername() + (u.getCurrentAuthority() != null ? " (" + u.getCurrentAuthority() + ")" : ""); } } if (exception != null) sLog.warn(message); else sLog.info(message); } if (exception != null) { if (exception instanceof PageAccessException && request instanceof HttpServletRequest && response instanceof HttpServletResponse) { HttpServletRequest r = (HttpServletRequest) request; HttpServletResponse x = (HttpServletResponse) response; String message = exception.getMessage(); if (message == null || message.isEmpty()) { HttpSession s = r.getSession(); if (getUser() == null) { if (s.isNew()) message = "Your timetabling session has expired. Please log in again."; else message = "Login is required to use this page."; } else { message = "Insufficient user privileges."; } } x.sendRedirect(x.encodeURL(r.getContextPath() + "/loginRequired.do?message=" + message)); } else if (exception instanceof ServletException) { throw (ServletException) exception; } else if (exception instanceof IOException) { throw (IOException) exception; } else if (exception instanceof RuntimeException) { throw (RuntimeException) exception; } else { throw new ServletException(exception); } } } finally { ApplicationProperties.setSessionId(null); } }
From source file:org.apache.struts.webapp.example.LinkSubscriptionRenderer.java
/** * <p>Render the beginning of our hyperlink element.</p> * * @param context FacesContext for the request we are processing * @param component UIComponent to be rendered * * @exception IOException if an input/output error occurs while rendering * @exception NullPointerException if <code>context</code> * or <code>component</code> is null *//*from www. j a va2 s . c o m*/ public void encodeBegin(FacesContext context, UIComponent component) throws IOException { if ((context == null) || (component == null)) { throw new NullPointerException(); } ResponseWriter writer = context.getResponseWriter(); HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest(); HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse(); String name = (String) component.getAttribute("name"); String page = (String) component.getAttribute("page"); // Generate the URL to be encoded StringBuffer url = new StringBuffer(request.getContextPath()); url.append(page); ApplicationFactory factory = (ApplicationFactory) FactoryFinder .getFactory(FactoryFinder.APPLICATION_FACTORY); Application application = factory.getApplication(); ValueBinding binding = application.getValueBinding(name); Subscription subscription = (Subscription) binding.getValue(context); if (subscription == null) { throw new FacesException("No subscription under attribute '" + name + "'"); } if (page.indexOf("?") < 0) { url.append("?"); } else { url.append("&"); } url.append("username="); url.append(ResponseUtils.filter(subscription.getUser().getUsername())); url.append("&host="); url.append(ResponseUtils.filter(subscription.getHost())); // Render the calculated hyperlink writer.write("<a href=\""); writer.write(response.encodeURL(url.toString())); writer.write("\">"); }