Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
java中的强制转换,request.getParameter_Java_Html - Fatal编程技术网

java中的强制转换,request.getParameter

java中的强制转换,request.getParameter,java,html,Java,Html,我很难理解为什么在下面的代码中,getParameter返回一个我需要将其转换为字符串的对象?在使用字符串时间时,我得到错误类型不匹配:无法从void转换为字符串。我不清楚是什么导致了这个错误,持续时间上的长数据类型还是用户上的字符串数据类型 public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {

我很难理解为什么在下面的代码中,getParameter返回一个我需要将其转换为字符串的对象?在使用字符串时间时,我得到错误类型不匹配:无法从void转换为字符串。我不清楚是什么导致了这个错误,持续时间上的长数据类型还是用户上的字符串数据类型

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);
}
public void doFilter(ServletRequest请求、ServletResponse响应、FilterChain链)抛出IOException、ServletException{
长t0=System.currentTimeMillis();
//沿着过滤器链传递请求
链式过滤器(请求、响应);
long t1=System.currentTimeMillis();
长持续时间=t1-t0;
字符串user=request.getParameter(“用户名”);
字符串timetake=System.out.println(“

在10.10.1.123从“+user+”发出的请求花费了“+duration+”ms

”; context.log(耗时); }

提前感谢。

System.out.println不返回任何内容,它只是将值打印到控制台。尝试使用不存在的返回值并将其保存到TimeTaked会显示错误消息

您可能只想将字符串指定给timetake

String timeTaken = "<HTML><BODY><P>Request from " + user + 
     " at 10.10.1.123 took " + duration + "ms </P></BODY></HTML>"; 
System.out.println(timeTaken);