JSP 代码错误 - 无法弄清楚原因
')' expected
out.println("Welcome "+myname+", <a href="logout.jsp\" >Logout</a>");
^
illegal character: \92
out.println("Welcome "+myname+", <a href="logout.jsp\" >Logout</a>");
^
我的所有 jsp 文件都在一个文件夹中,不确定为什么这是一个问题?
')' 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
logout.jsp 周围的引号需要转义。更改为:
The quotes around logout.jsp need to be escaped. Change to:
问题是您希望
显示在生成的 HTML 中,但您将其放在 Java 语句 (out.println) 中,而不是类似的内容。
那么问题是这
不是有效的 Java,因为引号对 Java 编译器意味着某些内容。
您可以在 HTML 中使用单引号,也可以告诉 Javac 这些引号没有任何意义。我推荐前者,因为代码更容易阅读:
The problem is that you want
to show up in your generated HTML, but you have it inside a Java statement (out.println) instead of being something like
The problem then is that
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:
这就是为什么您不在 JSP 中包含代码,因为正如您所发现的,它太容易犯愚蠢的错误。事实上,JSP 被转换为 *.java,其中有大量打印语句与“java 代码片段”混合在一起,这造成了混乱。
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.