html - Casting in java, request.getParameter -


i trying real hard understand why told getparameter returns object need cast string in following code? @ string timetaken error type mismatch: cannot convert void string. confused causing error, long datatype on duration or string datatype on user?

public void dofilter(servletrequest request, servletresponse response, filterchain chain) throws ioexception, servletexception {      long t0 = system.currenttimemillis();     // pass request along 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 " + user + " @ 10.10.1.123 took " + duration + "ms </p></body></html>");      context.log(timetaken); } 

thanks in advance.

system.out.println not return anything, prints value console. trying use non existing return value , save timetaken gives error message.

you want assign string timetaken;

string timetaken = "<html><body><p>request " + user +       " @ 10.10.1.123 took " + duration + "ms </p></body></html>";  

and possibly on following line if still want output string too;

system.out.println(timetaken); 

Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -