Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Java Beans, JSP and Access 2003 problem

Posted on 2008-11-06
2
Medium Priority
?
239 Views
Last Modified: 2013-12-29
I have problem with Access 2003 and Servlets

I have two beans:

MessageListBean and Message Bean;

A PageHandler class and a JSP page.

There are records in the tables message and actor and on the Single message page where I get just specific message record it works fine (SELECT * FROM message WHERE messageId=1).
When I try to get all records from the message table and to list them on the JSP page, nothing is returned.
No error messages.
Thanks,
Bill
public class MessageListBean {
    
    private ArrayList messages;
    
    /** Creates a new instance of MessageListBean */
    public MessageListBean() {
        messages = new ArrayList();
        i = 0;
    }
    public void addMessage (MessageBean message) {
        messages.add(message);
    }
    public ArrayList getMessages() {
        return messages;
    }
}
 
public class MessageBean {
    
    private String messageDate, subject, body, username, messageId, userImage;
    
    /** Creates a new instance of MessageBean */
    public MessageBean() {
        messageId="";
        body= "";
        subject="";
        username="";
        messageDate = "";
        userImage = "";
    }
    public String getMessageDate()
    {
        return messageDate;
    }
    public String getSubject()
    {
        return subject;
    }
    public String getBody()
    {
        return body;
    }
    public String getUsername()
    {
        return username;
    }
     public String getUserImage()
    {
        return userImage;
    }
    public String getMessageId()
    {
        return messageId;
    }
    public void setMessageDate(String mDate) throws Exception
    {  
        Date d = new SimpleDateFormat("yyyy-MM-dd").parse(mDate);
        messageDate = new SimpleDateFormat("dd-MM-yyyy").format(d);
    }
    
    public void setSubject(String subject)
    {
        this.subject = subject;
    }
    public void setBody(String body)
    {
        this.body = body;
    }
    public void setUsername(String username)
    {
        this.username = username;
    }
     public void setUserImage(String userImage)
    {
        this.userImage = userImage;
    }
    public void setMessageId(String messageId)
    {
        this.messageId = messageId;
    }
}
 
PageHandler class - processRequest method
 
 protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {    
        try
      {
        HttpSession mySession=request.getSession(true);
        //Validate if user is trying to avoid login
        
            MessageListBean MessageListBean = new MessageListBean();
            String order = request.getParameter("order");
 
            String orderText="ORDER BY messageDate DESC";
            if(order==null || order.trim().length()<1){
                orderText="ORDER BY messageDate DESC";
            }
            else {
               int o = new Integer(order).intValue();
                switch(o){
                    case 1: orderText="ORDER BY messageDate DESC";break;
                    case 2: orderText="ORDER BY messageDate ASC";break;
                    case 3: orderText="ORDER BY message.username DESC";break;
                    case 4: orderText="ORDER BY message.username ASC";break;
                    case 5: orderText="ORDER BY subject DESC";break;
                    case 6: orderText="ORDER BY subject ASC";break;
                }
 
            }
            ServletContext context = getServletContext();
            String appDirRoot = context.getRealPath("/");
            String connString = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)}; DBQ=" + appDirRoot + "forumDB.mdb";
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
            Connection connForum = DriverManager.getConnection(connString);
            Statement stmtMessages = connForum.createStatement();
            String sqlMessages = "SELECT * FROM message, actor WHERE message.username=actor.username " + orderText;
            ResultSet rsMessages = stmtMessages.executeQuery(sqlMessages);
           MessageBean message;
           int i=0;
            while (rsMessages.next())
            {
                i++;
               message = new MessageBean();
                message.setMessageDate(rsMessages.getString("messageDate"));
                message.setSubject(rsMessages.getString("subject"));
                message.setBody(rsMessages.getString("body"));
                message.setUsername(rsMessages.getString("username"));
                message.setMessageId("" + rsMessages.getInt("messageId") );
                message.setUserImage(rsMessages.getString("userImage"));
                MessageListBean.addMessage(message);
            }
            MessageListBean.setI(i);
            mySession.setAttribute("MessageListBean",MessageListBean);
           //mySession.setAttribute("c",i);
            connForum.close();
            response.sendRedirect("test.jsp");
          
        }
          catch (Exception e)
          {
             response.sendRedirect("default.jsp?message=Exception in MessageListGenerator");
          }   
    }
 
JSP page:
 
 <c:forEach items="${MessageListBean.messages}" var="message">
        <tr>
          <td colspan="3"></td>
          <td width="7%">
          <c:choose>
          <c:when test="${message.userImage!=null}">
            <img src="images/${message.userImage}" border="0" width="59" height="59">
          </c:when>
          <c:otherwise>
            <img src="images/default.gif" border="0" width="59" height="59"> 
          </c:otherwise>
          </c:choose>
          </td>
          <td colspan="3"><c:out value="${message.username}"/></td>
          <td colspan="2"><c:out value="${message.subject}"/></td>
          <td colspan="2" align="center"><a href="ViewMessage?messageId=${message.messageId}">View</a></td>
        </tr>
        </c:forEach>

Open in new window

0
Comment
Question by:bdimitry
2 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 22900709
>>response.sendRedirect("default.jsp?message=Exception in MessageListGenerator");

The above is incorrect btw (urls can't contain spaces)

You should really log an error and *then* do a redirect

Check server logs for errors you might have missed
0
 

Accepted Solution

by:
bdimitry earned 0 total points
ID: 23010003
I forgot to include a call in the JSP page  to the JSTL jar files.
Now it's working.
b.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month15 days, 3 hours left to enroll

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question