tom
tom

Reputation: 21

JSP code error - can't figure why

')' expected
out.println("Welcome "+myname+", <a href="logout.jsp\" >Logout</a>");
                                          ^

illegal character: \92
out.println("Welcome "+myname+", <a href="logout.jsp\" >Logout</a>");
                                                    ^

All my jsp files are in one folder, not sure why this is an issue?

Upvotes: 0

Views: 287

Answers (3)

The problem is that you want

<a href="something">

to show up in your generated HTML, but you have it inside a Java statement (out.println) instead of being something like

..%><a href="something"><%...

The problem then is that

out.println("<a href="something">");

is not valid Java because the quotes mean something to the Java compiler.

You can either use single quotes in your HTML or tell Javac that the quotes do not mean anything. I would recommend the former since the code is easier to read:

out.println("<a href='something'>");

Upvotes: 1

mP.
mP.

Reputation: 18266

This is why you dont include code in JSP, because its just too easy to make silly mistakes as you have discovered. The fact that the JSP is converted into a *.java with lots of print statements intermixed with your "java code snippets" makes for a royal mess.

Upvotes: 0

dogbane
dogbane

Reputation: 274532

The quotes around logout.jsp need to be escaped. Change to:

out.println("Welcome "+myname+", <a href=\"logout.jsp\" >Logout</a>");

Upvotes: 2

Related Questions