problem with servlet

Joined
Sep 4, 2007
Messages
1
Reaction score
0
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!
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top