我正在开发一个小型消息传递Web应用程序来学习jsp和servlet。我有一个MessageModel类,它具有以下属性:
String toAddress ;
String fromAddress;
String messageSubject;
String messageContent;
Timestamp messageTime;
int messageDraft;
和他们相应的jsp访问的setter。
我有一个查询数据库的方法,其中包含接收到要显示的特定地址的消息的所有消息。然后它创建一个新的MessageModel
对象并将其存储在ArrayList中。
public static ArrayList<MessageModel> getReceivedMessages(String toAddress) throws SQLException, ClassNotFoundException{
// creates a arraylist.
ArrayList<MessageModel> msgList = new ArrayList<MessageModel>();
// Database connection code..
// The query which gets the required messages from the database and adds them to the list.
String query = "SELECT * FROM messages WHERE msg_to='" + toAddress +"' ORDER BY msg_date DESC";
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);
if(rs.next()){
while(rs.next()){
String msgTo = rs.getString("msg_to");
String msgFrom = rs.getString("msg_from");
String msgSub = rs.getString("msg_subject");
String msgCnt = rs.getString("msg_matter");
Timestamp msgTime = rs.getTimestamp("msg_date");
MessageModel model = new MessageModel(msgTo,msgFrom,msgSub,msgCnt,msgTime);
msgList.add(model);
}
}
return msgList;
}
我从jsp中调用此方法,并使用
将列表另存为属性 String userName = (String) session.getAttribute("userId");
ArrayList<MessageModel> list = MessageModel.getReceivedMessages(userName);
pageContext.setAttribute("messageList", list);
但是当我通过<c:forEach>
标记访问列表中MesasgeModel对象的fromAddress属性时,出现以下错误:
javax.el.PropertyNotFoundException: Property 'fromAddress' not found on type com.email.system.MessageModel
这是HTML的一部分,访问打印出每个MessageModel
对象的内容。
<c:forEach items="${messageList}" var="message">
<li><c:out value="${message.toAddress}"/>
<c:out value="${message.messageSubject}"/> <c:out value="${message.messageTime}"/>
<c:out value="${message.messageContent}"/> <c:out value="${message.fromAddress}"/> </li>
</c:forEach>
每当我尝试访问toAddress
字段时都会发生错误。 toAddress属性存储在messageSubject
字段中,即使我在mySql控制台中尝试相同的查询时,我在各自的列中得到了正确的字段。
我删除内容列的查询的一个exapmle结果,
msg_id msg_to msg_from msg_subject msg_date msg_is_draft
4 bigb remember *subject* 2014-10-07 11:01:53 0
2 bigb remember *subject* 2014-10-07 10:48:43 0
1 bigb remember *subject* 2014-10-07 10:48:31 0
编辑:这是我的MessageModel
课程。
public class MessageModel {
String toAddress ;
String fromAddress;
String messageSubject;
String messageContent;
Timestamp messageTime;
int messageDraft;
public String getToAddress() {
return toAddress;
}
public String getFromAddress() {
return fromAddress;
}
public String getMessageSubject() {
return messageSubject;
}
public String getMessageContent() {
return messageContent;
}
public Timestamp getMessageTime() {
return messageTime;
}
public int getMessageDraft() {
return messageDraft;
}
public MessageModel(String toAddress,String fromAddress, String messageSubject, String messageContent,Timestamp messageTime){
this.toAddress = toAddress;
this.messageSubject = messageSubject;
this.messageContent = messageContent;
this.messageTime = messageTime;
this.fromAddress = fromAddress;
}
public void sendMessage(MessageModel model){
//Gets the related properties from the objects and stores it in the database
}
public static ArrayList<MessageModel> getReceivedMessages(String toAddress){
//Gets the messages sent to 'toAddress'
}
}
答案 0 :(得分:2)
如果对您在应用程序中使用的任何java源文件进行一些更改,则必须进行完全重建并重新部署以进行更改。
当我提出问题时,我的代码没有任何问题,而不是重新部署我只是更新资源。这只会更新对JSP而不是java源的更改。