说实话,这个问题弄了我2个多小时...
环境:ObjectWeb Lomboz for JavaEE Development Version: 3.1.2 JDK1.6 BETA
问题:100%没问题的JSP编译始终报错 甚至我感觉他更本就没有编译
信息:Syntax error on token(s), misplaced construct(s)
Syntax error on tokens, delete these tokens
ObjectWeb Lomboz for JavaEE Development Version: 3.1.2 加了tomcat插件进来后的确遇到过很多奇怪的问题。比如 Run on server 的时候提示“no launchable artifact could be found”。到google去搜索。见了有一个朋友Email给官方,寻找问题的原因。有一段回复见下:
I suspect that you are having this problem because you have not placed the login.jsp page someplace inside the WebContent folder.
Unfortunately this message is being thrown from the class org.eclipse.wst.server.ui.internal.actions.RunOnServerActionDelegate and I am unable to provide a more meaningful message. You may want to file a bug against the wst.server component on this.
看到这里,差点就放弃了这个玩意。不得行,弄不好 始终睡不着。
在IDE里面找了一个多小时原因,(够傻的吧)。干脆跑下页面看有没有更详细的信息
果然收获了一堆信息:Syntax error on token(s), misplaced construct(s) Syntax error on tokens, delete these tokens
再到Google查询。搜索结果很少,幸运,至少还有遇到过这个问题的
他提供了SUN官方网站的说明:
Without this step, the JSP servlet uses the JDT compiler, and will seemingly ignore most of the options in the web.xml configuration file.
Once you change these jar files, you should be using the javac compiler, but the JSP servlet will still be invoking it in 1.3 mode.
Now, update your <catalina_home>/conf/web.xml file so that the JSP servlet invokes the javac compiler to expect Java 1.5 constructs, and to generate Java 1.5 output. Do this by adding the init-params compilerSourceVM and compilerTargetVM, both with values of 1.5.
The JSP servlet section of web.xml should look like this:
原来是tomcat编译器的问题。NND的估计他默认是1.4版本的
解决办法:
1)http://ant.apache.org/bindownload.cgi下 ant.zip 的包 然后把里边的 ant.jar 复制到 /common/lib
2)删除 /common/lib/jasper-compiler-jdt.jar
3)找到Tomcat 5.5\conf 这个目录下的web.xml 里面有一段:
<servlet>
<servlet-name>jsp</servlet-name>
<servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
<init-param>
<param-name>fork</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>xpoweredBy</param-name>
<param-value>false</param-value>
</init-param>
<load-on-startup>3</load-on-startup>
</servlet>
4) 把这段注释掉 改成下面这段。 注意我写的是1.6。如果你是1.5的话可以尝试改成1.5
<servlet>
<servlet-name>jsp</servlet-name>
<servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
<init-param>
<param-name>fork</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>xpoweredBy</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>compilerSourceVM</param-name>
<param-value>1.6</param-value>
</init-param>
<init-param>
<param-name>compilerTargetVM</param-name>
<param-value>1.6</param-value>
</init-param>
<load-on-startup>3</load-on-startup>
</servlet>
刚修改完, 这回的确能编译了。又出来一个问题。页面是乱码了。乱码到是小问题 原理简单
控制台提示[错误:读取 D:\java\jdk1.6\jre\lib\ext\localedata.pack 时出错;error in opening zip file] 我也不清楚这个文件里面到底写的什么。SUN的官方有相关的BUG报告 ID: 6353586 把他改成.rar后居然正常了。看来他的作用也不大。不过鉴于它和JDK的关系,还是没忍心干掉他
NND这几天遇到的怪问题多得很。都没时间一一写下来
经过两次改造,感觉已经挖干了这只猫的“五脏六腑” 不过他还挺能折腾的
2006-03-19 Goingmm