gpt4 book ai didi

java - 如何修复 'HTTP Status 500 - Internal Server Error' 错误?

转载 作者:行者123 更新时间:2023-12-01 11:56:18 25 4
gpt4 key购买 nike

我正在运行 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?

我尝试清除网络浏览器的缓存和 Cookie(FireFox 和 Chrome),但此错误并没有消失。

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

“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'文件:

<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>

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

最佳答案

错误消息非常清楚:

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?

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

因为您发布的 Members 类中没有 personal 字段,我猜您在代码中混淆了某些内容,并且可能想访问不同类中的字段.

关于java - 如何修复 'HTTP Status 500 - Internal Server Error' 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28423609/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com