problem with servlet

Discussion in 'Java' started by odelyag, Sep 4, 2007.

  1. odelyag

    odelyag

    Joined:
    Sep 4, 2007
    Messages:
    1
    Hi,
    I wrote the following filter and wrapper:
    * filters parameters: ContentType and expires.
    */
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    if (filterConfig == null) {
    return;
    }
    long startTime = System.currentTimeMillis();

    HttpServletResponse res = (HttpServletResponse) response;
    HttpServletRequest req = (HttpServletRequest) request;
    JPServletResponseWrapper responseWrapper = new JPServletResponseWrapper(res);

    chain.doFilter(req, responseWrapper);

    String result = responseWrapper.toString();

    PrintWriter out = response.getWriter();

    int length = result.length() >= 10000 ? 10000 : result.length();
    int jpHTTPHeaderTag = result.substring(0, length).indexOf("jp-http-header");
    if (jpHTTPHeaderTag != -1) {
    int contentTypeIndex = result.indexOf("Content-type", jpHTTPHeaderTag);
    int contentTypeIndexStart = result.indexOf("#", contentTypeIndex);
    int contentTypeIndexEnd = result.indexOf("#", contentTypeIndexStart + 1);
    String contentType = result.substring(contentTypeIndexStart + 1, contentTypeIndexEnd);
    res.setContentType(contentType);
    out.write(result);
    } else {
    out.write(result);
    }
    out.close();

    long stopTime = System.currentTimeMillis();
    System.out.println("Time to execute request: " + (stopTime - startTime) + " milliseconds");

    }
    public void init(FilterConfig config) {
    filterConfig = config;
    }
    public void destroy() {
    filterConfig = null;

    }

    but when condition to set the content type as from the html file applies,
    res.setContentType(contentType) - doesn't do anything!
    odelyag, Sep 4, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andy Fish
    Replies:
    4
    Views:
    2,406
    Andy Fish
    Dec 17, 2003
  2. Sean Clarke
    Replies:
    1
    Views:
    1,881
    Sudsy
    Jan 7, 2004
  3. circuit_breaker
    Replies:
    2
    Views:
    1,984
    Jack Jia
    Apr 4, 2004
  4. chamikara
    Replies:
    1
    Views:
    49,834
  5. DiscoStu
    Replies:
    0
    Views:
    494
    DiscoStu
    Jul 8, 2004
Loading...

Share This Page