我通过创建动态Web项目,在Eclispe中使用Struts 2框架创建了一个Web应用程序。
我收到以下错误:
HTTP Status 500 - Internal Server Error
type Exception report
messageInternal Server Error
description The server encountered an internal error that prevented it from fulfilling this request. exception org.apache.jasper.JasperException: tag 'combobox', field 'list', name 'register.title': You must specify a collection/array/map/enumeration/iterator. Example: people or people.{name} - [unknown location]
root cause
tag 'combobox', field 'list', name 'register.title': You must specify a collection/array/map/enumeration/iterator. Example: people or people.{name} - [unknown location]
note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 4.1 logs.
以下是我的Java类和JSP
Register.java:
package Entities;
import java.util.Date;
public class Register {
private String text;
private String value;
private String title;
private String firstNm;
private String middleNm;
private String lastNm;
private String gender;
private Date dob;
private String emailAddress;
private String last4digitsSSN;
public Register() { super(); }
public Register(String text, String value) {
super();
this.text = text;
this.value = value;
}
public String getText() { return text; }
public void setText(String text) { this.text = text; }
public String getValue() { return value; }
public void setValue(String value) { this.value = value; }
public String getTitle() { return title; }
public void setTitle(String title) { this.title = title; }
public String getFirstNm() { return firstNm; }
public void setFirstNm(String firstNm) { this.firstNm = firstNm; }
public String getMiddleNm() { return middleNm; }
public void setMiddleNm(String middleNm) { this.middleNm = middleNm; }
public String getLastNm() { return lastNm; }
public void setLastNm(String lastNm) { this.lastNm = lastNm; }
public String getGender() { return gender; }
public void setGender(String gender) { this.gender = gender; }
public Date getDob() { return dob; }
public void setDob(Date dob) { this.dob = dob; }
public String getEmailAddress() { return emailAddress; }
public void setEmailAddress(String emailAddress) { this.emailAddress = emailAddress; }
public String getLast4digitsSSN() { return last4digitsSSN; }
public void setLast4digitsSSN(String last4digitsSSN) { this.last4digitsSSN = last4digitsSSN; }
}
RegisterModel.java:
import java.util.ArrayList;
import java.util.List;
import Entities.Register;
public class RegisterModel {
private List<Register> titlesList = new ArrayList<Register>();
private List<Register> gender = new ArrayList<Register>();
public List<Register> getTitles() {
titlesList.add(new Register("Mr.", "Mr."));
titlesList.add(new Register("Mrs.", "Mrs."));
titlesList.add(new Register("Ms.", "Ms."));
return titlesList;
}
public List<Register> getSex() {
gender.add(new Register("Male", "Male"));
gender.add(new Register("Female", "Female"));
return gender;
}
public List<Register> getTitlesList() { return titlesList; }
public void setTitlesList(List<Register> titlesList) { this.titlesList = titlesList; }
public List<Register> getGender() { return gender; }
public void setGender(List<Register> gender) { this.gender = gender; }
}
RegisterController.java:
package Controllers;
import java.util.ArrayList;
import java.util.List;
import com.opensymphony.xwork2.ActionSupport;
import Entities.Register;
import Models.RegisterModel;
public class RegisterController extends ActionSupport {
private static final long serialVersionUID = 1L;
private RegisterModel registerModel = new RegisterModel();
private List<Register> titlesList;
private List<Register> gender;
private Register register = new Register();
public String exec() {
this.titlesList = registerModel.getTitles();
this.gender = registerModel.getSex();
return SUCCESS;
}
public List<Register> getTitlesList() { return titlesList; }
public void setTitlesList(List<Register> titlesList) { this.titlesList = titlesList; }
public RegisterModel getRegisterModel() { return registerModel; }
public void setRegisterModel(RegisterModel registerModel) { this.registerModel = registerModel; }
public Register getRegister() { return register; }
public void setRegister(Register register) { this.register = register; }
public List<Register> getGender() { return gender; }
public void setGender(List<Register> gender) { this.gender = gender; }
}
Register.jsp:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@taglib uri="/struts-tags" prefix="s" %>
<%@taglib uri="/struts-dojo-tags" prefix="sx" %>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<sx:head />
<title>Registration Page</title>
</head>
<body>
<s:include value="Header.html" />
<s:form action="registration" method="POST">
<s:label cssStyle="font-weight: bold; padding-bottom: 10px;">Please enter a complete information below to register!</s:label>
<s:combobox label="Title" list="titlesList" listKey="text" listValue="value" name="register.title" headerKey="-1" headerValue="Select a title ..."></s:combobox>
<s:textfield label="First Name" name="register.firstNm" />
<s:textfield label="Middle Name" name="register.middleNm" />
<s:textfield label="Last Name" name="register.lastNm" />
<s:radio label="Gender" list="gender" name="register.gender" />
<sx:datetimepicker label="Date of Birth" name="register.dob" displayFormat="MM/dd/yyyy" />
<s:textfield label="E-mail Address" name="register.emailAddress" />
<s:password label="Last 4 Digits of SSN" name="last4digitsSSN" />
<s:password label="Password" />
<s:submit value="Register" />
</s:form>
<br />
<s:actionerror cssClass="error" />
</body>
</html>
struts.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<package name="" namespace="/" extends="struts-default">
<action name="registration"
class="Controllers.RegisterController" method="exec">
<result name="success">/Main/Register.jsp</result>
</action>
</package>
</struts>
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID"
version="3.1">
<display-name>WebApp</display-name>
<welcome-file-list>
<welcome-file>/Main/Login.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
2个JAR文件包含在库中:struts2-core-2.3.24.1.jar&amp; struts2的-道场-plugin.2.3.24.1.jar
我该如何解决此错误?