eclipse 如何修复“HTTP 状态 500 - 内部服务器错误”错误?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28423609/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 22:24:07  来源:igfitidea点击:

How can I fix 'HTTP Status 500 - Internal Server Error' error?

javaeclipsespring-mvcglassfishtomcat8

提问by 7d0

I am running Spring MVC project, and I receive this 'HTTP Status 500 - Internal Server Error' with the following information below:

我正在运行 Spring MVC 项目,并且收到此“HTTP 状态 500 - 内部服务器错误”,其中包含以下信息:

type: Exception report
message: Internal Server Error
description: The server encountered an internal error that prevented it from fulfilling this request.
exception: 
          org.apache.jasper.JasperException: org.springframework.beans.NotReadablePropertyException: Invalid property 'personal' of bean class [com.demo.7d0.Members]: Bean property 'personal' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
root cause: 
           org.springframework.beans.NotReadablePropertyException: Invalid property 'personal' of bean class [com.demo.7d0.Members]: Bean property 'personal' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?

I tried to clear the web browsers' cache & cookies (FireFox & Chrome), but this error does not go away.

我试图清除网络浏览器的缓存和 cookie(FireFox 和 Chrome),但此错误并未消失。

I run this project on GlassFish 4. I received the same 'HTTP Status 500 - Internal Server Error' on Tomcat 8 as well.

我在 GlassFish 4 上运行这个项目。我在 Tomcat 8 上也收到了相同的“HTTP 状态 500 - 内部服务器错误”。

'Members.java' class:

'Members.java' 类:

public class Members {

@NotEmpty(message = "* 'First Name' is required!")
@Size(min = 2, max = 30)
public String firstName;

@NotEmpty(message = "* 'Middle Name' is required!")
public String middleName;

@NotEmpty(message = "* 'Last Name' is required!")
public String lastName;

@Pattern(regexp = "^([Male]{4})|([Femal]{6})$", message = "* Please select a gender!")
public String gender;   

@Pattern(regexp = "^[0-2]{1,2}\/[0-9]{1,2}\/[0-9]{4}$", message = "* Invalid date of birth. Please follow the provided example!")
public String dob;  

@Pattern(regexp = "^[\w\-]+(\.[\w\-]+)*@([A-Za-z0-9-]+\.)+[A-Za-z]{2,4}$", message = "* E-mail address is not correct!")
@NotEmpty(message = "* E-mail address is required!")    
public String emailAddress; 

@Pattern(regexp = "^[0-9]{4,4}$", message = "* 'Last 4 digits of SSN' has an incorrect format. Please follow the provided example!")
public String last4digitsSSN;

@Pattern(regexp = "^([0-9]{1}\s?\-\s?)?\(\d{3}\)\s?\d{3}\s?\-\s?\d{4}$", message = "* 'Phone Number' has an incorrect format. Please follow the provided example!")
public String phoneNumber;

@Pattern(regexp = "^([MobilePhn\s]{12})|([HomePhn\s]{10})|([WorkPhne\s]{10})$", message = "* Please select a phone type!")
public String phoneType;

@Pattern(regexp = "^([Student]{7})|([Profes]{9})|([Cashier]{7})|([OficeClrk\s]{12})|([Manger]{7})|([Superviso]{10})|([Acounta]{10})|([Other]{5})$", message = "* Please select an occupation!")
public String occupation;

@Pattern(regexp = "^([Yes]{3})|([No]{2})$", message = "* Are you US Citizen? Please answer!")
public String usCitizen;

@Pattern(regexp = "^([Yes]{3})|([No]{2})$", message = "* Are you at least 18 years old? Please answer!")
public String atLeast18YrsOld;  

@Pattern(regexp = "^[a-zA-Z0-9\s\.\'\-]{2,35}$", message = "* Invalid address!")
@NotEmpty(message = "* Address is Required!")
private String address1;

//@Pattern(regexp = "^[a-zA-Z0-9\s\.\'\-]$", message = "* Invalid address!")
private String address2;

//@Pattern(regexp = "^[a-zA-Z0-9\s\.\'\-]$", message = "* Invalid address!")
private String address3;

@Pattern(regexp = "^[a-zA-Z\.\s\-\']{1,18}$", message = "* Invalid name for city field!")
@NotEmpty(message = "* Please enter a name for city field!")
private String city;

@Pattern(regexp = "^[a-zA-Z\s\-\']{1,15}$", message = "* Invalid name for state field!")
@NotEmpty(message = "* Please enter a name for state field!")
private String state;

//@Pattern(regexp = "^([0-9]{5,5}|([0-9-]{10,10}))", message = "Postcode is not correct!")
@Pattern(regexp = "^\d{5}([\-\d]{5})?$", message = "* Postcode is not correct!")
private String zipcode;

@Pattern(regexp = "^[a-zA-Z\.\s\-\']{1,25}$", message = "* Invalid name for country field!")
@NotEmpty(message = "* Please enter a name for country field!")
private String country;

@Size(min = 2, max = 30)
private String usrnm;

@Size(min = 2, max = 30)
private String pwd; 

@Pattern(regexp = "^([Mr\.]{3})|([Mrs\.]{4})|([Ms\.]{3})$", message = "* Please select a title!")
@NotEmpty(message="* Title is required!")
private String title;

private String comment; 

@Pattern(regexp = "^[0-2]{1,2}\/[0-9]{1,2}\/[0-9]{4}$", message = "* Invalid date of registration. Please follow the provided example!")
private String registrationDate;

@Pattern(regexp = "^[A-Z]{1}([a-zA-Z]{1})?[A-Z]{1}$", message = "* Initials has an incorrect format. Please follow the provided example!")
@NotEmpty(message = "* Initials is required!")
@Size(min = 1, max = 3, message = "* Initials size must be between 1 character & 3 characters!")
private String initials;

public void setFirstName(String firstName) {
    this.firstName = firstName;
}

public String getFirstName() {
    return firstName;
}

public void setMiddleName(String middleName) {
    this.middleName = middleName;
}

public String getMiddleName() {
    return middleName;
}

public void setLastName(String lastName) {
    this.lastName = lastName;
}

public String getLastName() {
    return lastName;
}

public void setGender(String gender) {
    this.gender = gender;
}

public String getGender() {
    return gender;
}

public void setDob(String dob) {
    this.dob = dob;
}

public String getDob() {
    return dob;
}

public void setEmailAddress(String emailAddress) {
    this.emailAddress = emailAddress;
}

public String getEmailAddress() {
    return emailAddress;
}

public void setLast4digitsSSN(String last4digitsSSN) {
    this.last4digitsSSN = last4digitsSSN;
}

public String getLast4digitsSSN() {
    return last4digitsSSN;
}

public void setPhoneNumber(String phoneNumber) {
    this.phoneNumber = phoneNumber;
}

public String getPhoneNumber() {
    return phoneNumber;
}

public void setPhoneType(String phoneType) {
    this.phoneType = phoneType;
}

public String getPhoneType() {
    return phoneType;
}

public void setOccupation(String occupation) {
    this.occupation = occupation;
}

public String getOccupation() {
    return occupation;
}

public void setUsCitizen(String usCitizen) {
    this.usCitizen = usCitizen;
}

public String getUsCitizen() {
    return usCitizen;
}   

public void setAtLeast18YrsOld(String atLeast18YrsOld) {
    this.atLeast18YrsOld = atLeast18YrsOld;
}   

public String getAtLeast18YrsOld() {
    return atLeast18YrsOld;
}

public void setAddress1(String address1) {
    this.address1 = address1;
}

public String getAddress1() {
    return address1;
}

public void setAddress2(String address2) {
    this.address2 = address2;
}

public String getAddress2() {
    return address2;
}

public void setAddress3(String address3) {
    this.address3 = address3;
}

public String getAddress3() {
    return address3;
}

public void setCity(String city) {
    this.city = city;
}

public String getCity() {
    return city;
}

public void setState(String state) {
    this.state = state;
}

public String getState() {
    return state;
}

public void setZipcode(String zipcode) {
    this.zipcode = zipcode;
}

public String getZipcode() {
    return zipcode;
}

public void setCountry(String country) {
    this.country = country;
}

public String getCountry() {
    return country;
}

public void setUsrnm(String usrnm) {
    this.usrnm = usrnm;
}

public String getUsrnm() {
    return usrnm;
}   

public void setPwd(String pwd) {
    this.pwd = pwd;
}

public String getPwd() {
    return pwd;
}   

public void setTitle(String title) {
    this.title = title;
}

public String getTitle() {
    return title;
}

public void setComment(String comment) {
    this.comment = comment;
}

public String getComment() {
    return comment;
}

public void setRegistrationDate(String registrationDate) {
    this.registrationDate = registrationDate;
}

public String getRegistrationDate() {
    return registrationDate;
}

public void setInitials(String initials) {
    this.initials = initials;
}

public String getInitials() {
    return initials;
}

@Autowired
DataSource sqlserverDataSrc;

public void insert(String title, String firstName, String middleName,
                   String lastName, String gender, Date dob,
                   String emailAddress, int last4digitsSSN, String phoneNum,
                   String phoneType, String address1, String address2,
                   String address3, String city, String state,
                   String postcode, String country, String usrnm,
                   String pwd, String occupation, boolean usCitizen,
                   boolean atLeast18yrsOld, String comment, Date registrationDate,
                   String initials) {

    String sqlQuery = "INSERT INTO Members "
                    + "VALUES(?, ?, ?," + 
                            " ?, ?, ?," + 
                            " ?, ?, ?," +
                            " ?, ?, ?," + 
                            " ?, ?, ?," + 
                            " ?, ?, ?," + 
                            " ?, ?, ?," + 
                            " ?, ?, ?," + 
                            " ?);";

    JdbcTemplate jdbcTemplate = new JdbcTemplate(sqlserverDataSrc);
    jdbcTemplate.update(sqlQuery, new Object[] {title, firstName, middleName,
                                                lastName, gender, dob,
                                                emailAddress, last4digitsSSN, phoneNum,
                                                phoneType, address1, address2,
                                                address3, city, state,
                                                postcode, country, usrnm, 
                                                pwd, occupation, usCitizen, 
                                                atLeast18yrsOld, comment, registrationDate, 
                                                initials});
}

public void delete(String usrnm, String pwd, int last4digitsSSN) {

    String sqlQuery = "DELETE FROM Members WHERE usrnm = '" + usrnm 
                    + "' AND pwd = '" + pwd 
                    + "' AND last4digitsSSN = " + last4digitsSSN + ";";

    JdbcTemplate jdbcTemplate = new JdbcTemplate(sqlserverDataSrc);
    jdbcTemplate.update(sqlQuery);
}

public void update(String usrnm, String pwd, int last4digitsSSN) {

    String sqlQuery = "UPDATE Members SET pwd = ? WHERE usrnm = ? AND last4digitsSSN = ?";

    JdbcTemplate jdbcTemplate = new JdbcTemplate(sqlserverDataSrc);
    jdbcTemplate.update(sqlQuery, new Object[] {pwd, usrnm, last4digitsSSN});
}
}

'spring-servlet.xml' file:

'spring-servlet.xml' 文件:

<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:context="http://www.springframework.org/schema/context"  
   xmlns:mvc="http://www.springframework.org/schema/mvc"     
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://www.springframework.org/schema/beans
                       http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                       http://www.springframework.org/schema/context
                       http://www.springframework.org/schema/context/spring-context-3.0.xsd
                       http://www.springframework.org/schema/mvc
                       http://www.springframework.org/schema/mvc/spring-mvc.xsd">

<context:annotation-config />

<!-- declaring base package -->
<context:component-scan base-package="com.demo.7d0" />

<mvc:annotation-driven />        

<mvc:resources mapping="/CSS/**" location="/CSS/" />    

<bean id="ViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix">
        <value>/WEB-INF/Views/</value>
    </property>

    <property name="suffix">
        <value>.jsp</value>
    </property>
</bean>       

<bean id="sqlserverDataSrc"
      class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
    <property name="url" value="jdbc:sqlserver://7d0\SQLSERVER:1433;databaseName=demo" />
    <property name="username" value="sa" />
    <property name="password" value="pwd" />
</bean>

<bean id="messageSource" 
      class="org.springframework.context.support.ReloadableResourceBundleMessageSource">

    <property name="basename" value="/WEB-INF/messages"></property>
</bean>
</beans>

How should I fix this error? Thanks!

我应该如何修复这个错误?谢谢!

回答by unwichtich

The error message is pretty clear:

错误信息非常清楚:

Invalid property 'personal' of bean class [com.demo.7d0.Members]: Bean property 'personal' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?

bean 类 [com.demo.7d0.Members] 的属性“个人”无效:Bean 属性“个人”不可读或具有无效的 getter 方法:getter 的返回类型是否与 setter 的参数类型匹配?

Somewhere in your code you are trying to access this property of the Membersclass. Search this place in your code to fix the problem.

在您的代码中,您正试图访问Members该类的此属性。在您的代码中搜索此位置以解决问题。

Because there is no personalfield in the Membersclass you posted, I guess you mixed something up in your code and maybe wanted to access a field from a different class.

因为您发布personalMembers课程中没有字段,我猜您在代码中混淆了某些内容,并且可能想要访问来自不同课程的字段。