Let me ask you a basic question about servlet response.(T)

Asked 1 years ago, Updated 1 years ago, 384 views

        String data = "<html>";
            data += "<body>";
            data += "ID:" + id;
            data += "<br>";
            data += "Password:" + pw;
            data += "</body>";
            data += "</html>";
        out.print(data);

I don't understand this part. In the first line, <html> was added to the String type data. I connected all the strings with data += below that, then

data = data + "<body>"
data = data + "ID:"+ id

It's connected like this, right?

where data += overrides all data in each row, so

Eventually, if you say out.print(data) at the end, if you don't turn the forword, the data value is substituted at the end. Shouldn't only </html> be printed?

java

2023-01-09 11:12

1 Answers

String data = "qwe";
data += "asd"; 
// data = data + equal to "asd"

In the code above, data+="asd" does not refer to "asd" as "asd", but rather to connect "asd" to "qwe" already assigned to the data.

Therefore:

System.out.println(data); // qweasd 출력

That's what happens.


2023-01-09 21:59

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.