开发者

JSP code error - can't figure why

开发者 https://www.devze.com 2023-02-08 22:34 出处:网络
\')\' expected out.println(\"Welcome \"+myname+\", <a href=\"logout.jsp\\\" >Logout</a>\");
')' 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?


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

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


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'>");


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消