Hi guys! New question about the topic! I wrote next java classes and
jsp:
These codes for inbox messages: I wanna that when user goes to inbox link he sees inbox messages, but it keeps giving me nex error:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: An exception occurred processing JSP page /inbox.jsp at line 80
77: site.Message[] mess = (Message[]) request.getAttribute("table");
78:
79: int num = 0;
80: for (int i = 0; i < mess.length; i++) {
81: num++;
82: %>
83: <%= "<tr>"%>
Here is the code:
Database acsess for messages:
public Message[] readMessage(Message mess) throws ServletException {
{
try {
PreparedStatement b = this.connection.prepareStatement(
"SELECT"
+ " fromname,"
+ " toname, "
+ " date, "
+ " messagetext, "
+ " FROM sas.messages WHERE username=?");
b.setString(1, mess.getFromuser());
b.setString(2, mess.getTouser());
b.setString(3, mess.getDate());
b.setString(4, mess.getMessage());
ResultSet resultSet = b.executeQuery();
ArrayList<Message> collecMess = new ArrayList<Message>();
while (resultSet.next()) {
Message sqlMess = new Message();
sqlMess.setFromuser(resultSet.getString("fromname"));
sqlMess.setTouser(resultSet.getString("toName"));
sqlMess.setDate(resultSet.getString("date"));
sqlMess.setMessage(resultSet.getString("message"));
collecMess.add(sqlMess);
}
Message[] resultMess = collecMess.toArray(new Message[collecMess.size()]);
return resultMess;
} catch (SQLException e) {
throw new ServletException("sql exception", e);
}
}
}
servlet readMess:
public class readMess extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Message mess = new Message();
mess.setUsername(request.getParameter("username"));
mess.setFromuser(request.getParameter("fromuser"));
mess.setTouser(request.getParameter("touser"));
mess.setDate(request.getParameter("date"));
mess.setMessage((request.getParameter("message")));
DatabaseAccess DataBaseCon = new DatabaseAccess();
RequestDispatcher view = request.getRequestDispatcher("inbox.jsp");
request.setAttribute("ifTrue", DataBaseCon.readMessage(mess));
view.forward(request, response);
}
and jsp:
<form id="read_mess" action="readMess" method="post"></form>
<table border="1">
<tr>
<th>Username</th>
<th>From</th>
<th>To</th>
<th>Message</th>
</tr>
<%
site.Message[] mess = (Message[]) request.getAttribute("table");
int num = 0;
for (int i = 0; i < mess.length; i++) {
num++;
%>
<%= "<tr>"%>
<%= "<td align=\"center\">"%><%= mess[i].getUsername()%><%= "</td>"%>
<%= "<td align=\"center\">"%><%= mess[i].getFromuser()%><%= "</td>"%>
<%= "<td align=\"center\">"%><%= mess[i].getTouser()%><%= "</td>"%>
<%= "<td align=\"center\">"%><%= mess[i].getMessage()%><%= "</td>"%>
<%= "</tr>"%>
<% }%>
</table>
</div>
</body>