Line break by toString() in Java
drsbmm
-
AL_UMPC -
AL_UMPC -
Hello everyone,
well... I have a question, in Java:
I have the following class;
class Person {
private String lastName;
private String firstName;
public Person(String lastName, String firstName) {
this.lastName = lastName;
this.firstName = firstName;
}
public String toString() {
return ("last name: " + lastName + "\n" + "first name: " + firstName);
}
}
In the JSP when I want to display an object of type Person using:
<%
Person per = new Person("dodo", "toto");
out.println("<h4>" + per + "</h4>");
%>
The problem is:
instead of the result being in the form:
last name: dodo
first name: toto
it displays as: "last name: dodo first name: toto " it ignores the line break
Please help me !!!
well... I have a question, in Java:
I have the following class;
class Person {
private String lastName;
private String firstName;
public Person(String lastName, String firstName) {
this.lastName = lastName;
this.firstName = firstName;
}
public String toString() {
return ("last name: " + lastName + "\n" + "first name: " + firstName);
}
}
In the JSP when I want to display an object of type Person using:
<%
Person per = new Person("dodo", "toto");
out.println("<h4>" + per + "</h4>");
%>
The problem is:
instead of the result being in the form:
last name: dodo
first name: toto
it displays as: "last name: dodo first name: toto " it ignores the line break
Please help me !!!
Configuration: Windows XP Internet Explorer 7.0