\n is within a string...

String str = request.getParameter("textfieldvalue");

I want to display the value of str to other pages..using this link below.

window.open("page.jsp?param=<%=str%>")

....the problem is that the window is not opening due the str has \n.


How to read \n in a string?

\n is within a string...

String str = request.getParameter("textfieldvalue");

I want to display the value of str to other pages..using this link below.

window.open("page.jsp?param=<%=str%>")

....the problem is that the window is not opening due the str has \n.


How to read \n in a string?

I don't know if it will work, but try to replace the char: '\n' which is in the String with this: <br>

You can apply trim() method on the given string to trim leading and trailing whitespaces. Also since str forms a part of the URL, make sure you URL encode the string so that special characters are taken care of [e.g. &, ; etc.].

One question though: How did a newline character manage to find its way into a text field?

can't believe I didn't think of this, great solution!

I was creating an XML style string, and I did this just like you suggested:

"&lt/soapenv:Header&gt" + "<br></br>";

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.