說(shuō)實(shí)話(huà),這個(gè)問(wèn)題弄了我2個(gè)多小時(shí)...
環(huán)境:ObjectWeb Lomboz for JavaEE Development Version: 3.1.2 JDK1.6 BETA
問(wèn)題:100%沒(méi)問(wèn)題的JSP編譯始終報錯 甚至我感覺(jué)他更本就沒(méi)有編譯
信息: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插件進(jìn)來(lái)后的確遇到過(guò)很多奇怪的問(wèn)題。比如 Run on server 的時(shí)候提示“no launchable artifact could be found”。到google去搜索。見(jiàn)了有一個(gè)朋友Email給官方,尋找問(wèn)題的原因。有一段回復見(jiàn)下:
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.
看到這里,差點(diǎn)就放棄了這個(gè)玩意。不得行,弄不好 始終睡不著(zhù)。
在IDE里面找了一個(gè)多小時(shí)原因,(夠傻的吧)。干脆跑下頁(yè)面看有沒(méi)有更詳細的信息
果然收獲了一堆信息:Syntax error on token(s), misplaced construct(s) Syntax error on tokens, delete these tokens
再到Google查詢(xún)。搜索結果很少,幸運,至少還有遇到過(guò)這個(gè)問(wèn)題的
他提供了SUN官方網(wǎng)站的說(shuō)明:
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:
原來(lái)是tomcat編譯器的問(wèn)題。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 這個(gè)目錄下的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) 把這段注釋掉 改成下面這段。 注意我寫(xiě)的是1.6。如果你是1.5的話(huà)可以嘗試改成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>
剛修改完, 這回的確能編譯了。又出來(lái)一個(gè)問(wèn)題。頁(yè)面是亂碼了。亂碼到是小問(wèn)題 原理簡(jiǎn)單
控制臺提示[錯誤:讀取 D:\java\jdk1.6\jre\lib\ext\localedata.pack 時(shí)出錯;error in opening zip file] 我也不清楚這個(gè)文件里面到底寫(xiě)的什么。SUN的官方有相關(guān)的BUG報告 ID: 6353586 把他改成.rar后居然正常了??磥?lái)他的作用也不大。不過(guò)鑒于它和JDK的關(guān)系,還是沒(méi)忍心干掉他
NND這幾天遇到的怪問(wèn)題多得很。都沒(méi)時(shí)間一一寫(xiě)下來(lái)
經(jīng)過(guò)兩次改造,感覺(jué)已經(jīng)挖干了這只貓的“五臟六腑” 不過(guò)他還挺能折騰的
2006-03-19 Goingmm
聯(lián)系客服