最近打算学习一下JSP,用了几分钟配置好jdk和tomcat之后,就开始了愉快的coding,直到。。。我敲到一个表达式输出的例程的时候,问题出现了。大概程序就是这样的一个简单的程序:
<%@page contentType="text/html; charset=UTF-8" language = "java"%> <!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xthml11/DTD/xhtml11=transitional.dtd"> <html xmlns = "http://www.h3.org/1999/xhtml"> <head> <meta http-equiv = "Content-Type" content = "text/html;charset=UTF-8"> <title>综合演示页面</title> </head> <body> <%--声明--%> <%! String s= "这里一个String类型的变量"; String t(){ return "这是一个方法的返回值"; } class Demo{ public String sayHello(){ return "这里是类方法的返回值"; } } %> <%--脚本--%> <% String s1 = s; String s2 = t(); Demo demo = new Demo(); String s3 = demo.sayHello(); %> <%--利用表达式输出--%> <p><% =s1%></p> <p><%=s2%></p> <p><%=s3%></p> </body> </html>
当我非常愉快的到浏览器去查看localhost下的界面的时候,突然出现了500报错,报错信息包含:
Type Exception Report
Message Unable to compile class for JSP:
Description The server encountered an unexpected condition that prevented it from fulfilling the request.
Exception
org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: [29] in the jsp file: [/all.jsp] Syntax error on token "=", @ expected 26: String s3 = demo.sayHello(); 27: %> 28: <%--鍒╃敤琛ㄨ揪寮忚緭鍑�--%> 29: <p><% =s1%></p> 30: <p><%=s2%></p> 31: <p><%=s3%></p> 32: </body>
嗨呀,提示29行=出错,可是也没有出错啊?
然后我就在网上搜索了各路大神给出的解决方案。。然后,,,然后没有找到任何一种解决办法,直到我仔细看了一下代码之后。。
md。。。原来是20行多了一个空格。。。
只需要把29行<% =s1%>中的空格去掉,变成<%=s1%>即可。。。
哎,随手敲空格的习惯已经被python虐了一次了,这次jsp再虐我一次,应该是会长记性了。。。