Examples of HttpServletResponse


Examples of javax.servlet.http.HttpServletResponse

     * @throws UnsupportedEncodingException if the charset is not a valid encoding name
     */
    public synchronized void close(String defaultCharset) throws UnsupportedEncodingException {
        // if the response was already written and committed by the application
        // there's no point in closing the response buffer
        HttpServletResponse res = reqtrans.getServletResponse();
        if (res != null && res.isCommitted()) {
            // response was committed using HttpServletResponse directly. We need
            // set response to null and notify waiters in order to let attached
            // requests know they can't reuse this response.
            response = null;
            notifyAll();
View Full Code Here

Examples of javax.servlet.http.HttpServletResponse

   * @return          void
   */
  public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException
  {
    HttpServletRequest req = (HttpServletRequest)request;
    HttpServletResponse res = (HttpServletResponse)response;

    // Check to see if we are currently trying to log in.  If so, then let the request go.
    if ((request.getParameter("username") == null) && (request.getParameter("password") == null)) {
      // well we aren't trying to login in an obvious way, so check the session for a null UserObject
      HttpSession session = req.getSession(true);
      if ((UserObject)session.getAttribute("userobject") == null) {
        // Apparently we don't have a userObject.  Is this request trying to go to
        // a screen which doesn't require a valid logged-in user with a session?
        String servletPath = req.getServletPath();

        boolean isValidUrl = false;
        for (int i = 0; i < PopulateUserObject.validUrls.length; i++) {
          if (servletPath.equals(PopulateUserObject.validUrls[i])) {
            isValidUrl = true;
          }
        }

        if (! isValidUrl) {
          // nope.  Go Directly to Jail. Do not pass Go. Do not collect $200.
          req.getRequestDispatcher(res.encodeURL("/start.do")).forward(req, res);
        }
      } else if (session.getAttribute("expiredLicense") != null) {
        // okay, so we have a non null userobject on the session, BUT the license is expired
        // So the admin may be trying to dance without paying the piper.  But the chisler
        // didn't count on this filter.  He had better be trying to view or save the license and
        // that is all, or else there will be a repeat of that business that occurred in Hamelin.
        String requestURL = req.getServletPath();
        // SaveLicense.do or DisplayLicense.do or logout.do
        if (!(requestURL.matches("^/\\S+License.do$") || requestURL.matches("^/logout.do$"))) {
          // get back there and pay me!
          req.getRequestDispatcher(res.encodeURL("/DisplayLicense.do")).forward(req, res);
        }
      }
    }
    chain.doFilter(req, res);
  }   // end doFilter()
View Full Code Here

Examples of javax.servlet.http.HttpServletResponse

      }
    }
   
    ServletActionContext sc = (ServletActionContext) context;
    HttpServletRequest request = sc.getRequest();
    HttpServletResponse response = sc.getResponse();
    ServletContext servletContext = sc.getContext();
   
    ActionContext actionContext = actionContextFactory.createActionContext(request, response, servletContext,
        actionForm, (ActionMapping) actionConfig);
View Full Code Here

Examples of javax.servlet.http.HttpServletResponse

  public void render(ActionContext actionContext)
  {
    try
    {
      HttpServletRequest request = actionContext.getRequest();
      HttpServletResponse response = actionContext.getResponse();
      view.render(model, request, response);
    }
    catch (Exception e)
    {
      throw new ApplicationRuntimeException("Exception thrown during rendering of view "
View Full Code Here

Examples of javax.servlet.http.HttpServletResponse

   * @model
   */
  public ContentType encode(Packet packet, OutputStream out) throws IOException {
    if(gzip && packet.supports(MessageContext.SERVLET_REQUEST) &&
        isGzipInRequest((HttpServletRequest)packet.get(MessageContext.SERVLET_REQUEST))){
      HttpServletResponse response = (HttpServletResponse)packet.get(MessageContext.SERVLET_RESPONSE);
      if(!response.isCommitted()){
        response.addHeader("Content-Encoding", "gzip");
        out = new GZIPOutputStream(out);
      }
    }
    try {
      // MessageContext.MESSAGE_OUTBOUND_PROPERTY set by JAX_WS only if handler configured. But encode always a out bound.
View Full Code Here

Examples of javax.servlet.http.HttpServletResponse

        e.printStackTrace();
        System.out
            .println("========================================================");
      }
    } finally {
      HttpServletResponse hResponse = (HttpServletResponse) servletResponse;
      String fileUrl = StringUtils.join(fileNames, ",");
      hResponse.sendRedirect(this.finishUrl
          + "?fileUrl='" + fileUrl + "'");
    }
  }
View Full Code Here

Examples of javax.servlet.http.HttpServletResponse

   * @param servletResponse
   */
  public void process(ServletRequest servletReqest,
      ServletResponse servletResponse) throws Throwable {
    HttpServletRequest request = (HttpServletRequest) servletReqest;
    HttpServletResponse response = (HttpServletResponse) servletResponse;

    // 获取字符编码
    this.charset = request.getCharacterEncoding();
    if (this.charset == null || charset.trim().equals("")) {
      this.charset = "UTF-8";
View Full Code Here

Examples of javax.servlet.http.HttpServletResponse

  public void doFilter(ServletRequest servletReqest,
      ServletResponse servletResponse, FilterChain filterChain)
      throws IOException, ServletException {

    HttpServletRequest hRequest = (HttpServletRequest) servletReqest;
    HttpServletResponse hResponse = (HttpServletResponse) servletResponse;

    if (this.sessionServerUrl != null) {
      // 检测当前应用是否充当了会话服务器的职能,如果是,则直接进入下一个过滤器
      boolean isSessionServerUrl = this.sessionServerUrl.replace(
          hRequest.getRequestURL().toString(), "").trim().equals("");
      if (isSessionServerUrl) {
        filterChain.doFilter(hRequest, hResponse);
        return;
      }

      HttpSession session = hRequest.getSession();
      // 从当前会话中获取snaId
      String snaId = (String) session
          .getAttribute(SNAIdRequestServlet.SNA_ID);
      if (snaId == null) {// 如果没有标识,则尝试从参数中获取
        snaId = hRequest.getParameter(SNAIdRequestServlet.SNA_ID);
      }

      String queryString = hRequest.getQueryString();
      // 如果snaId为null,则重定向到sna会话服务器,获取新的snaId
      if (snaId == null || snaId.trim().equals("")) {
        if (queryString != null && !queryString.equals(""))
          queryString = "&" + queryString;
        else
          queryString = "";

        // 从SNA会话服务器上获取snaId
        String redirectUrl = this.sessionServerUrl + "?sourceUrl="
            + hRequest.getRequestURL() + ";jsessionid="
            + session.getId() + queryString;
        hResponse.sendRedirect(redirectUrl);
        return;
      }

      // 保存snaId到当前会话
      if (session.getAttribute(SNAIdRequestServlet.SNA_ID) == null) {
        session.setAttribute(SNAIdRequestServlet.SNA_ID, snaId);

        // 构造查询参数
        queryString = queryString.replaceAll(SNAIdRequestServlet.SNA_ID
            + "=" + snaId, "");
        if (queryString.startsWith("&"))
          queryString = queryString.replaceFirst("&", "?");
        // 重定向回原始页面
        hResponse.sendRedirect(hRequest.getRequestURL() + queryString);
        return;
      }
    }

    String uri = hRequest.getRequestURI();
View Full Code Here

Examples of javax.servlet.http.HttpServletResponse

    protected boolean excludedPath(String path) {
      return hasText(path) && (path.contains("/jawr") || path.contains("/resource") || path.contains("/captcha"));
    }

    protected HttpServletResponse compress(String pathInfo, HttpServletRequest request, HttpServletResponse response) {
      HttpServletResponse compressed = response;
      if (request.getAttribute(GZIPPED_RESPONSE) == null) {
            request.setAttribute(GZIPPED_RESPONSE, true);
            String acceptGzip = request.getHeader("accept-encoding");
            if ((acceptGzip != null) && (acceptGzip.indexOf("gzip") != -1) && (!GZIPResponseWrapper.class.isInstance(response)))
              if (!excludedPath(pathInfo))
View Full Code Here

Examples of javax.servlet.http.HttpServletResponse

        wod.load();
       
        DcObject dco = wod.getDcObject();
        String filename = dco.getFilename();
        File file = new File(filename);
        HttpServletResponse response = (HttpServletResponse) fc.getExternalContext().getResponse();

        int read = 0;
        byte[] bytes = new byte[1024];
        response.setContentType("application/data");
        response.setHeader("Content-Disposition", "attachment;filename=\"" + file.getName() + "\"");
       
        try {
            FileInputStream fis = new FileInputStream(file);
            OutputStream os = response.getOutputStream();
            while((read = fis.read(bytes)) != -1){
                os.write(bytes,0,read);
            }
            os.flush();
            os.close();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.