JDK1.5 jsp里 List list = new Vector()这样写被tomcat5提示错误 为什么啊?

hengdda 2005-04-04 08:44:15
有多少人遇到这样的问题?
我的jdk1.5 tomcat5.58
<%
List<Integer> list = new Vector<Integer>();
for (int i = 0; i < 6; i++)
{
list.add(i);
}
for (Integer i : list) {
out.print(i * 100);
out.print("===");
}
%>
无法运行 提示我

An error occurred at line: 24 in the jsp file: /test.jsp
Generated servlet error:
Syntax error on token "<", invalid AssignmentOperator

An error occurred at line: 24 in the jsp file: /test.jsp
Generated servlet error:
Syntax error on token "=", != expected

An error occurred at line: 24 in the jsp file: /test.jsp
Generated servlet error:
Syntax error on token "<", ( expected

An error occurred at line: 24 in the jsp file: /test.jsp
Generated servlet error:
Syntax error on token "(", invalid Expression

An error occurred at line: 24 in the jsp file: /test.jsp
Generated servlet error:
Syntax error on token(s), misplaced construct(s)

An error occurred at line: 24 in the jsp file: /test.jsp
Generated servlet error:
Syntax error on token ")", : expected

但是我如果老实的按照 1.4时代的写法

List list = new Vector();
..............
for (Iterator i= list.iterator(); i.hasNext();)
{
.......
}

就没有出错了~请大虾指点 是那里的问题呢?
...全文
170 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
hengdda 2005-04-04
  • 打赏
  • 举报
回复
http://forum.java.sun.com/thread.jspa?threadID=579806&messageID=3044385

多谢taglib 我在sun那里找到比较详细的说明和方法了~

真的比较麻烦 需要先从这里http://ant.apache.org/bindownload.cgi
下 ant.zip 的包 然后把里边的 ant.jar 复制到<cataline_home>/common/lib.
并且删除
<catalina_home>common/lib/jasper-compiler-jdt.jar

-----瞧原文,必须这么做,没这步不行。。
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:
-------------------接着修改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>
<init-param>
<param-name>compilerSourceVM</param-name>
<param-value>1.5</param-value>
</init-param>
<init-param>
<param-name>compilerTargetVM</param-name>
<param-value>1.5</param-value>
</init-param>
<load-on-startup>3</load-on-startup>
</servlet>
hengdda 2005-04-04
  • 打赏
  • 举报
回复
可以的,List是接口~
其实问题不在与是否list
Vecotr<Integer> myvector=new Vector<Integer>();
.....
for(Integer i:myvector)
{
out.print(i);
}

即使你这样也一样不行 我就奇怪了 为什么提示 Syntax error?
我把这段放在servlet下实验,可以运行成功 可是怎么到了jsp下就提示语法错误呢?

如果换成老的1.4的写法
Vector myv=new Vecotr();
.....
for(Iterator i=myv.iterator;i.hasNext())
{
out.print(i);
}在jsp下就没有问题了 可以运行正确结果.
我感觉就是这个 Vector<integer> 时候 这个 <integer> 出了问题 可不知道为什么会这样
1.5不就是要求这么写的?
taglib 2005-04-04
  • 打赏
  • 举报
回复
把/conf/web.xml里的compilerSourceVM改成1.5,默认是1.4, 参考
http://www.jetaware.com/tomcat-docs/jasper-howto.html
MARS.nEIL 2005-04-04
  • 打赏
  • 举报
回复
有这种写法吗?List<Integer> list = new Vector<Integer>();

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧