I have the following class
A JAVA FILE(data)
package p1;
class data
{
private String pro;
private String sta;
public void set1(String a)
{
pro=a;
}
public void set2(String b)
{
sta=b;
}
}
A class file to retrive data from db
A JAVA FILE(conb)
package p1;
import java.sql.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.*;
import p1.*;
public class conb
{
public static List<data> datadb() throws SQLException
{
List<data> n1=new ArrayList<data>();
Connection conn = null;
Statement st = null;
try
{
String userName = "frank";
String password = "asdf";
String url = "jdbc:mysql://localhost:8080/work";
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
conn = DriverManager.getConnection (url, userName, password);
}
catch (Exception e)
{
e.printStackTrace();
}
try {
st = conn.createStatement();
st.execute("select * from work1");
ResultSet rs = st.getResultSet();
while(rs.next())
{
data d1=new data();
d1.set1(rs.getString("pron"));
d1.set2(rs.getString("sdata"));
n1.add(d1);
}
rs.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
finally
{
if (conn != null)
{
try
{
conn.close ();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
return n1;
}
}
This files are in WEB-INF/Classes/p1
And i want to display the data in a jsp file (using jsp as controller and view)
I am using tomcat 6.0 in windows.
I have written jsp page also for this
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ import "java.util.*" %>
<%@ import "p1.conb" %>
<!doctype HTML public "-//W3C//DTD HTML 4.0 Frameset//EN">
</head>
<body>
<table cellpadding="2" cellspacing="2" width="100%">
<tr>
<td>Name</td>
<td>Start time</td>
</tr>
<tr>
<%
List<data> da1 = new List<data>();
da1=p1.conb.datadb();
%>
<c:forEach items="${da1}" >
<td><c:out value="{$da1.pro}" /></td>
<td><c:out value="{$da1.sta}" /></td>
</tr>
</c:forEach>
</table>
<html>
<head>
I am getting errors
how can i retrive the data from database using only jsp.
I dont want to use a servlet as a controller.
The errors are:
org.apache.jasper.JasperException: org.apache.jasper.JasperException: Unable to load class for JSP org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:1??61) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:340) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260) javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…