How does javascript's alert box display multiple lines in Java


If you are directly in javascript code, you can display multiple lines with \n:


alert(" The first line n The second line ");

But in Java code, \n doesn’t work, \\n shows multiple lines!!


String strTemp=" History report: \n"+" You are right "+RdData.getCcnt()+" problem \n"+" Do you have "+RdData.getBcnt()+" No answer \n"+" You wrong "+RdData.getWcnt()+" The topic \n";
out.print("<script> alert('"+strTemp+"');window.location='index.jsp'</script>");

First, a String variable is declared (note that the newline is \\n!!). , and then put it in alert, and when you’re done, the page jumps to the home page.

Here are the test results:   This is the special character code in javascript:


Code Outputs
' single quote
" double quote
\ backslash
n new line
r carriage return
t tab
b backspace
f form feed