我真的很难理解为什么我被告知 getParameter 返回一个我需要将其转换为以下代码中的字符串的对象?在 String timeTaken 我收到错误 Type mismatch: cannot convert from void to String。我对导致错误的原因感到困惑,持续时间的长数据类型或用户的字符串数据类型?
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
long t0 = System.currentTimeMillis();
// pass the request along the filter chain
chain.doFilter(request, response);
long t1 = System.currentTimeMillis();
long duration = t1 - t0;
String user = request.getParameter("userName");
String timeTaken = System.out.println("<HTML><BODY><P>Request from " + user + " at 10.10.1.123 took " + duration + "ms </P></BODY></HTML>");
context.log(timeTaken);
}
提前致谢。