我試圖用javax.servlet.Filter
來查看一條消息。如何從過濾器中窺探Mesage?
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
BufferedReader reader = request.getReader();
if (reader.markSupported()) {
reader.mark(contentLen);
}
String content = reader.readLine();
// search some pattern
if (reader.markSupported()) {
reader.reset();
}
chain.doFilter(request, response);
}
終於接收到請求該servlet引發此exeption:
java.lang.IllegalStateException: getReader() has already been called for this request
其爲根據的Javadoc正確的行爲。
我的問題是我怎樣才能讀取輸入流的內容呢?
我也試過ServletInputStream is = request.getInputStream();
能否克隆請求,然後看看克隆? – 2012-02-13 10:53:21