Package javax.servlet.http

Examples of javax.servlet.http.HttpServletResponse


        if (view == null){
            return;
        }
       
        HttpServletRequest request = viewContext.getRequest();
        HttpServletResponse response = viewContext.getResponse();
        String controllerPath = viewContext.getControllerPath();
        String actionName = viewContext.getActionName();
       
        if (view.getContentType() != null){
            response.setContentType(view.getContentType());
        }
       
        for(Entry<String,Object> entry: view.getAttributes().entrySet()){
            request.setAttribute(entry.getKey(), entry.getValue());
        }
View Full Code Here


    public void renderView(BinaryView view, ViewContext viewContext) throws Exception{
        if (view == null){
            return;
        }
       
        HttpServletResponse response = viewContext.getResponse();
        response.setContentType(view.getContentType());
        response.setContentLength(view.getData().length);
        if (view.getFileName() == null){
            response.setHeader("Content-Disposition", view.getContentDisposition());
        }
        else{
            String filename = new String(view.getFileName().getBytes("GBK"), "ISO8859_1");
            response.setHeader("Content-Disposition", view.getContentDisposition()+";filename="+filename);
        }
        OutputStream out = response.getOutputStream();
        out.write(view.getData());
        out.close();
    }
View Full Code Here

    public void renderView(JsonView view, ViewContext viewContext) throws Exception{
        if (view == null){
            return;
        }
       
        HttpServletResponse response = viewContext.getResponse();
        if (view.getContentType() != null){
            response.setContentType(view.getContentType());
        }
        else{
            response.setContentType("application/json;charset=utf-8");
        }
        PrintWriter out = response.getWriter();
        out.print(view.toString());
        out.close();
    }
View Full Code Here

            initConfiguration(cfg, viewContext);
            servletContext.setAttribute(FreeMarkerViewRenderer.FREEMARKER_CONFIG, cfg);
        }
       
        HttpServletRequest request = viewContext.getRequest();
        HttpServletResponse response = viewContext.getResponse();
        String controllerPath = viewContext.getControllerPath();
       
        Enumeration<?> attrNames = request.getAttributeNames();
        while(attrNames.hasMoreElements()){
            String attr = (String)attrNames.nextElement();
            Object value = request.getAttribute(attr);
            view.setAttribute(attr, value);
        }
       
        String path = view.getPath();
        if (path == null){
            path = controllerPath.toLowerCase() + "/" + viewContext.getActionName() + ".ftl";
        }
        else{
            if (path.indexOf("/") == -1){
                path = controllerPath.toLowerCase() + "/" + path;
            }
            else if (!path.startsWith("/")){
                path = "/" + path;
            }
            if (!path.endsWith(".ftl")){
                path += ".ftl";
            }
        }
       
        if (view.getContentType() != null){
            response.setContentType(view.getContentType());
        }
       
        Template t = cfg.getTemplate(path, request.getLocale());
        t.process(view.getAttributes(), response.getWriter());
    }
View Full Code Here

    public void renderView(TextView view, ViewContext viewContext) throws Exception{
        if (view == null){
            return;
        }
       
        HttpServletResponse response = viewContext.getResponse();
        if (view.getContentType() != null){
            response.setContentType(view.getContentType());
        }
        PrintWriter out = response.getWriter();
        out.print(view.toString());
        out.close();
    }
View Full Code Here

        }
*/
        // handle dev response
        if (this.developmentMode && !context.getResponseComplete()
                && resp instanceof HttpServletResponse) {
            HttpServletResponse httpResp = (HttpServletResponse) resp;
            httpResp.reset();
            httpResp.setContentType("text/html; charset=UTF-8");
            Writer w = httpResp.getWriter();
            DevTools.debugHtml(w, context, e);
            w.flush();
            context.responseComplete();
        } else if (e instanceof RuntimeException) {
            throw (RuntimeException) e;
View Full Code Here

    public void doFilter(ServletRequest request, ServletResponse response,
                         FilterChain chain)
  throws IOException, ServletException {

        HttpServletRequest req = (HttpServletRequest)request;
        HttpServletResponse res = (HttpServletResponse)response;
       
        // 设置默认编码为UTF-8
        req.setCharacterEncoding("UTF-8");
        res.setContentType("text/html;charset=UTF-8");
       
        RequestContext requestContext = new RequestContext();
        requestContext.setControllerBasePackage(Dispatcher.getControllerBasePackage());
        requestContext.setControllerPaths(Dispatcher.getControllerPaths());
        requestContext.setRequest(req);
View Full Code Here

            chain.doFilter(req, res);
            return;
        }

        HttpServletRequest request = (HttpServletRequest) req;
        HttpServletResponse response = (HttpServletResponse) res;

        // Redirect requests with JSESSIONID in URL to clean version (old links bookmarked/stored by bots)
        // This is ONLY triggered if the request did not also contain a JSESSIONID cookie! Which should be fine for bots...
        if (request.isRequestedSessionIdFromURL()) {
            String url = request.getRequestURL()
                         .append(request.getQueryString() != null ? "?"+request.getQueryString() : "")
                         .toString();
            // TODO: The url is clean, at least in Tomcat, which strips out the JSESSIONID path parameter automatically (Jetty does not?!)
            response.setHeader("Location", url);
            response.sendError(HttpServletResponse.SC_MOVED_PERMANENTLY);
            return;
        }

        // Prevent rendering of JSESSIONID in URLs for all outgoing links
        HttpServletResponseWrapper wrappedResponse =
View Full Code Here

    }
    StringBuffer buffer = new StringBuffer();
    buffer.append(request.getContextPath());
    buffer.append(context.getPath(action));

    HttpServletResponse response =
      (HttpServletResponse)pageContext.getResponse();
    return response.encodeURL(buffer.toString());
  }
View Full Code Here

                    synchronized (req.getSession()) {
                        String url = navigationManager.getCurrentPage();
                        String rewrittenUrl = ((urlRewriter != null) ? urlRewriter.rewriteUrl(url) : url);
                        String fullUrl = req.getContextPath() + rewrittenUrl;
                        HttpServletResponse res = (HttpServletResponse) servletResponse;
                        res.sendRedirect(fullUrl);
                    }
                }
            }
        }
    }
View Full Code Here

TOP

Related Classes of javax.servlet.http.HttpServletResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.