简体   繁体   English

Java EE中的for-each循环和泛型

[英]for-each loops and generics in Java EE

I am designing a website-based project wherein I first designed my logical layer in Java SE application development. 我正在设计一个基于网站的项目,其中首先设计了Java SE应用程序开发中的逻辑层。 Then I made the GUI in Java EE for the website. 然后,我使用Java EE为该网站制作了GUI。 I am importing my Java SE files in the Java EE architecture using JSTL and I will call the data using this only. 我正在使用JSTL将Java SE文件导入Java EE体系结构,并且仅使用此文件来调用数据。

But, it is giving me an error as follows: 但是,这给了我一个错误,如下所示:

  1. for-each loops -- for-each loops are not used in source 1.4, try source 1.5 to enable for-each loop. for-each循环- for-each loops are not used in source 1.4, try source 1.5 to enable for-each loop.
  2. generics -- generics are not supported in source 1.4, try source 1.5 to enable generics 泛型- generics are not supported in source 1.4, try source 1.5 to enable generics
  3. variable-arity methods are not supported in -source 1.4

It appears you have the wrong JDK selected - all those features were added in JDK 1.5. 看来您选择了错误的JDK-所有这些功能都已在JDK 1.5中添加。 Make sure you have the 1.5 JDK selected for both your IDE, and your web application App Server. 确保为IDE和Web应用程序App Server选择了1.5 JDK。 This should resolve your problem. 这应该可以解决您的问题。

In Netbeans the Java EE format is part of the project settings. 在Netbeans中,Java EE格式是项目设置的一部分。 Unfortunately it can't be changed in the project settings once you have created the project. 不幸的是,一旦创建了项目,就无法在项目设置中对其进行更改。

Create a new project with the Java EE 5 version and copy your source across. 使用Java EE 5版本创建一个新项目,并在其中复制源代码。

To be able to select Java EE 5, you will need a Java EE 5 capable server installed, eg. 为了能够选择Java EE 5,您将需要安装具有Java EE 5的服务器,例如。 Tomcat v6 or GlassFish v2. Tomcat v6或GlassFish v2。 You can install the servers using the NetBeans Tools->Servers menu. 您可以使用NetBeans工具->服务器菜单安装服务器。

If you are building via Ant or by the command line, ensure that you specify " -source 1.5 " on the javac command line. 如果要通过Ant或通过命令行进行构建,请确保在javac命令行上指定“ -source 1.5 ”。 Also, JSP files will not necessarily use Java 5 features by default. 另外,默认情况下,JSP文件不一定会使用Java 5功能。 This depends on what Servlet standard you're using. 这取决于您使用的Servlet标准。 For example, see this blog entry that tells you how to set Tomcat 5.5 so it will allow 1.5 features in its JSPs. 例如,请参阅此博客条目 ,其中告诉您如何设置Tomcat 5.5,以便它将在其JSP中允许1.5功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM