I am using tomat 7.0.8. I am trying to access basic information in a database using the DAO (direct access object) design pattern. The problem I am having is that the data shows fine when I use a servlet. However, when trying to use a jsp file (which is preferred) I get an error that says the DAO object is not a recognized type. Here are the details:
Working Servlet:
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
public class ShowQuestions extends HttpServlet
{
public void service(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
try
{
BrainDAO dao = BrainDAO_Concrete.getBrainDAO();
ArrayList questions = dao.getQuestions(1,1);
Questions questionAndAnswers;
res.setContentType("text/html");
String html = "<html>";
html += "<head><title>Form Output</title></head>";
html +="<body>";
html +="<h3>Questions</h3>";
for (Iterator i = questions.iterator(); i.hasNext();)
{
questionAndAnswers = (Questions)i.next();
html+= "Question is : " + questionAndAnswers.getQuestion() + "<br />";
html += "A " + questionAndAnswers.getAnswerW1() + "<br />";
html += "B " + questionAndAnswers.getAnswerW2() + "<br />";
html += "C " + questionAndAnswers.getAnswerW3() + "<br />";
html += "D " + questionAndAnswers.getAnswerR() + "<br />";
}
html += "</body></html>";
res.getWriter().println(html);
}
catch(IOException sqle) {
System.out.println(sqle);
}
catch(ClassNotFoundException cnfe) {
System.out.println(cnfe);
}
catch(SQLException sqle) {
System.out.println(sqle);
}
}
}
Jsp That does not work
<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*, java.util.*, java.io.*" errorPage="" %>
<!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=utf-8" />
<title>Questions JSP</title>
</head>
<body>
<%
try
{
BrainDAO dao = BrainDAO_Concrete.getBrainDAO();
ArrayList questions = dao.getQuestions(1,1);
%>
<table><tr><td><b>Question</b></td><td><b>Ans1</b></td><td><b>Ans2</b></td><td><b>Ans3</b></td><td><b>Ansr</b></td></tr>
<%
Questions questionAndAnswers;
for (Iterator i = questions.iterator(); i.hasNext();)
{
questionAndAnswers = (Questions)i.next();
%>
<tr><td>
<%=questionAndAnswers.getQuestion() %>
</td><td>
<%=questionAndAnswers.getAnswerW1()%>
</td><td>
<%=questionAndAnswers.getAnswerW2()%>
</td></tr>
<%=questionAndAnswers.getAnswerW3()%>
</td></tr>
<%=questionAndAnswers.getAnswerR()%>
</td></tr>
<% } //end of iteration
}//end of try block
catch(IOException sqle)
{
System.out.println(sqle);
}
catch(ClassNotFoundException cnfe)
{
System.out.println(cnfe);
}
catch(SQLException sqle)
{
System.out.println(sqle);
}
%>
</table>
</body>
</html>
Up to this point I have not been using Ant or any kind of deployment software. I manually created my root folder brain(C:\Tomcat7.0\webapps\brain) and in it are my jsp files. The WEB-INF folder that has the classes folder, in which are all the classes, is also in brain.(C:\Tomcat7.0\webapps\brain\WEB-INF\classes). To ensure clarity here is the main part of the error message that Tomcat spits out:
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 13 in the jsp file: /questions.jsp
BrainDAO cannot be resolved to a type
10: <%
11: try
12: {
13: BrainDAO dao = BrainDAO_Concrete.getBrainDAO();
14: ArrayList questions = dao.getQuestions(1,1);
15: %>
16: