生成的servlet错误:-source 1.5不支持默认方法(使用-source 8或更高版本启用默认方法)

问题描述 投票:0回答:1

我正在使用Netbeans 8.2版本来练习我的spring MVC项目。netbeans提供的默认IDK版本是1.8,我正在使用这个项目来学习表单验证。我正在使用这个项目所需的所有库,包括旧版本,我在这里使用的服务器是 GlassFish 4.1.1。

我的错误在这里:

HTTP Status 500 - Internal Server Error

type Exception report

messageInternal Server Error

descriptionThe server encountered an internal error that prevented it from fulfilling this request.

exception 
org.apache.jasper.JasperException: PWC6033: Error in Javac compilation for JSP

PWC6199: Generated servlet error:
source value 1.5 is obsolete and will be removed in a future release

PWC6199: Generated servlet error:
target value 1.5 is obsolete and will be removed in a future release

PWC6199: Generated servlet error:
To suppress warnings about obsolete options, use -Xlint:-options.

PWC6199: Generated servlet error:
diamond operator is not supported in -source 1.5
  (use -source 7 or higher to enable diamond operator)

PWC6197: An error occurred at line: 23 in the jsp file: /WEB-INF/view/customer-form.jsp
PWC6199: Generated servlet error:
multi-catch statement is not supported in -source 1.5
  (use -source 7 or higher to enable multi-catch statement)

PWC6199: Generated servlet error:
diamond operator is not supported in -source 1.5
  (use -source 7 or higher to enable diamond operator)

PWC6199: Generated servlet error:
diamond operator is not supported in -source 1.5
  (use -source 7 or higher to enable diamond operator)

PWC6199: Generated servlet error:
default methods are not supported in -source 1.5
  (use -source 8 or higher to enable default methods)

PWC6199: Generated servlet error:
default methods are not supported in -source 1.5
  (use -source 8 or higher to enable default methods)

PWC6197: An error occurred at line: 5 in the jsp file: /WEB-INF/view/customer-form.jsp
PWC6199: Generated servlet error:
diamond operator is not supported in -source 1.5
  (use -source 7 or higher to enable diamond operator)

PWC6199: Generated servlet error:
diamond operator is not supported in -source 1.5
  (use -source 7 or higher to enable diamond operator)

PWC6199: Generated servlet error:
lambda expressions are not supported in -source 1.5
  (use -source 8 or higher to enable lambda expressions)

PWC6199: Generated servlet error:
try-with-resources is not supported in -source 1.5
  (use -source 7 or higher to enable try-with-resources)

PWC6197: An error occurred at line: 41 in the jsp file: /WEB-INF/view/customer-form.jsp
PWC6199: Generated servlet error:
diamond operator is not supported in -source 1.5
  (use -source 7 or higher to enable diamond operator)

PWC6199: Generated servlet error:
diamond operator is not supported in -source 1.5
  (use -source 7 or higher to enable diamond operator)

PWC6199: Generated servlet error:
unknown enum constant javax.annotation.meta.When.MAYBE
  reason: class file for javax.annotation.meta.When not found

PWC6199: Generated servlet error:
diamond operator is not supported in -source 1.5
  (use -source 7 or higher to enable diamond operator)

PWC6199: Generated servlet error:
diamond operator is not supported in -source 1.5
  (use -source 7 or higher to enable diamond operator)

PWC6199: Generated servlet error:
lambda expressions are not supported in -source 1.5
  (use -source 8 or higher to enable lambda expressions)

PWC6199: Generated servlet error:
diamond operator is not supported in -source 1.5
  (use -source 7 or higher to enable diamond operator)

PWC6197: An error occurred at line: 23 in the jsp file: /WEB-INF/view/customer-form.jsp
PWC6199: Generated servlet error:
lambda expressions are not supported in -source 1.5
  (use -source 8 or higher to enable lambda expressions)

PWC6199: Generated servlet error:
diamond operator is not supported in -source 1.5
  (use -source 7 or higher to enable diamond operator)

PWC6199: Generated servlet error:
multi-catch statement is not supported in -source 1.5
  (use -source 7 or higher to enable multi-catch statement)

PWC6199: Generated servlet error:
lambda expressions are not supported in -source 1.5
  (use -source 8 or higher to enable lambda expressions)

PWC6199: Generated servlet error:
diamond operator is not supported in -source 1.5
  (use -source 7 or higher to enable diamond operator)

PWC6197: An error occurred at line: 23 in the jsp file: /WEB-INF/view/customer-form.jsp
PWC6199: Generated servlet error:
diamond operator is not supported in -source 1.5
  (use -source 7 or higher to enable diamond operator)

PWC6199: Generated servlet error:
default methods are not supported in -source 1.5
  (use -source 8 or higher to enable default methods)

PWC6199: Generated servlet error:
lambda expressions are not supported in -source 1.5
  (use -source 8 or higher to enable lambda expressions)

PWC6197: An error occurred at line: 5 in the jsp file: /WEB-INF/view/customer-form.jsp
PWC6199: Generated servlet error:
diamond operator is not supported in -source 1.5
  (use -source 7 or higher to enable diamond operator)

PWC6197: An error occurred at line: 23 in the jsp file: /WEB-INF/view/customer-form.jsp
PWC6199: Generated servlet error:
default methods are not supported in -source 1.5
  (use -source 8 or higher to enable default methods)

PWC6197: An error occurred at line: 25 in the jsp file: /WEB-INF/view/customer-form.jsp
PWC6199: Generated servlet error:
default methods are not supported in -source 1.5
  (use -source 8 or higher to enable default methods)

PWC6199: Generated servlet error:
default methods are not supported in -source 1.5
  (use -source 8 or higher to enable default methods)

PWC6199: Generated servlet error:
diamond operator is not supported in -source 1.5
  (use -source 7 or higher to enable diamond operator)

PWC6199: Generated servlet error:
diamond operator is not supported in -source 1.5
  (use -source 7 or higher to enable diamond operator)

PWC6199: Generated servlet error:
lambda expression not expected here

PWC6197: An error occurred at line: 23 in the jsp file: /WEB-INF/view/customer-form.jsp
PWC6199: Generated servlet error:
lambda expression not expected here

PWC6199: Generated servlet error:
lambda expression not expected here

PWC6199: Generated servlet error:
lambda expression not expected here

PWC6197: An error occurred at line: 5 in the jsp file: /WEB-INF/view/customer-form.jsp
PWC6199: Generated servlet error:
default methods are not supported in -source 1.5
  (use -source 8 or higher to enable default methods)

PWC6199: Generated servlet error:
lambda expression not expected here

PWC6199: Generated servlet error:
diamond operator is not supported in -source 1.5
  (use -source 7 or higher to enable diamond operator)

PWC6197: An error occurred at line: 33 in the jsp file: /WEB-INF/view/customer-form.jsp
PWC6199: Generated servlet error:
diamond operator is not supported in -source 1.5
  (use -source 7 or higher to enable diamond operator)

GlassFish Server Open Source Edition 4.1.1 

我的 Customer.java 代码:

package springdemo.mvc;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
public class Customer {

    private String firstName;

    @NotNull(message="is required")
    @Size(min=2,message = "Field is required")
    private String lastName;

    @NotNull(message="is required")
    @Min(value=0,message="must be greater than or equal to zero")
    @Max(value=10,message="must be less than or equal to 10")
    private Integer freePasses;

    @Pattern(regexp="^[a-zA-Z0-9]{5}",message="only 5 chars/digit")
    private String postalCode;
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }
    public void setFreePasses(Integer freePasses) {
        this.freePasses = freePasses;
    }
    public void setPostalCode(String postalCode) {
        this.postalCode = postalCode;
    }    
    public String getFirstName() {
        return firstName;
    }
    public String getLastName() {
        return lastName;
    }
    public Integer getFreePasses() {
        return freePasses;
    }
    public String getPostalCode() {
        return postalCode;
    }       
}

我的 customer-form.jsp 文件:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Customer form</title>
        <style>
            .error{color:red}
        </style>
    </head>
    <body>
        <ul><li>Fill out the form. Asterisk(*) means required</li></ul>
        <form:form action="processForm" modelAttribute="customer">
            First Name : <form:input path="firstName"/>
            Last Name(*) : <form:input path="lastName"/>
            <p><form:errors name="lastName" cssClass="error"/></p>
            Free Passes = <form:input path="freePasses"/>
            <form:errors name="freePasses" cssClass="error"/>
            Postal Code = <form:input path="postalCode"/>
            <form:errors name="postalCode" cssClass="error"/>
            <form:input path="submit"/>
        </form:form></body></html>

请帮助我。

java spring-mvc jsp servlets netbeans-8
1个回答
0
投票

读完后我也遇到了同样的问题 https://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html

在pom.xml中我们需要设置源和目标,否则默认值太低

    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.12.1</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
    </plugins>
© www.soinside.com 2019 - 2024. All rights reserved.