wood burning stoves 2.0*
The moose likes Servlets and the fly likes Urgent, please help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Urgent, please help" Watch "Urgent, please help" New topic
Author

Urgent, please help

raja bhai
Greenhorn

Joined: Jun 23, 2001
Posts: 3
I am totally new to JSP.I know Java but not JSP.I was trying to show a table on the browser using JSP.I am using JBuilder and Tomcat webserver
here is the code I have written
test.jsp
<html>
<Body>
This is test.jsp
<p>
<form method = post action= "Test2.jsp">
<input type = submit>
</form>
</body>
</Html>
test2.jsp

<html>
<body>
<%@ page language="java" %>
<jsp:useBean id = "DbBean" scope="request" class="DbBean" />
<jsp:setProperty name="DbBean" property="*" />
the values from database
<table>
<tr><td>something</td></tr>
<%=DbBean.GetData() %>
</table>
</body>
</html>

DbBean.java
package testpackage;
import java.sql.*;
import java.io.*;
import java.util.*;
import java.text.*;
import java.beans.*;
import javax.servlet.http.HttpServlet;
import javax.servlet.jsp.*;
import org.apache.jasper.runtime.HttpJspBase;

public class DbBean
{
private String url = "jdbc dbc:JavaDSN";
private String Driver = "sun.jdbc.odbc.JdbcOdbcDriver" ;
private Connection con;
private Statement stmt;
private ResultSet rs;
public DbBean()
{
super();
}
public String GetData() throws ClassNotFoundException,SQLException
{
try
{
//registering the driver
Class.forName( Driver );
}catch(ClassNotFoundException e)
{
e.printStackTrace();
}
try
{
con = DriverManager.getConnection(url);
stmt = con.createStatement();
rs = stmt.executeQuery("Select * from Items");
}catch(SQLException e)
{
e.printStackTrace();
}
String RtnValue = "";
while(rs.next())
{
RtnValue = RtnValue +"<tr><td>" + rs.getString(1)+"</td>";
RtnValue = RtnValue+"<td>"+rs.getString(2)+"</td>";
RtnValue = RtnValue+"<td>"+rs.getString(3)+"</td>";
RtnValue = RtnValue+"<td>"+rs.getString(4)+"</td></tr>";
}
con.close();
return RtnValue;
}
}
In F:\jakarta-tomcat\jakarta-tomcat-3.1.1\jakarta-tomcat\webapps\examples\WEB-INF\classes
I have
DbBean.class
In F:\jakarta-tomcat\jakarta-tomcat-3.1.1\jakarta-tomcat\webapps\examples\mytests
I have
test.jsp test2.jsp
at http://localhost:8080/examples/mytests/Test2.jsp
I got the following error
Location: /examples/mytests/Test2.jsp
Internal Servlet Error:
java.lang.IllegalStateException: Response has already been committed
at org.apache.tomcat.core.HttpServletResponseFacade.sendError(HttpServletResponseFacade.java:157)
at org.apache.jasper.runtime.JspServlet.unknownException(JspServlet.java:299)
at org.apache.jasper.runtime.JspServlet.service(JspServlet.java:377)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.tomcat.core.ServletWrapper.handleRequest(ServletWrapper.java:503)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:559)
at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:160)
at org.apache.tomcat.service.TcpConnectionThread.run(SimpleTcpEndpoint.java:338)
at java.lang.Thread.run(Thread.java:484)
Please help. don't laugh at my ignorance.

Rajabhai
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
For one thing: since your class is in a package:
"package testpackage;"
You must import the package
instead of <%@ page language="java" %> use
<%@ page language="java" import="testpackage" %>
Furthermore, you must give the full package in the useBean tag:
instead of
<jsp:useBean id = "DbBean" scope="request" class="DbBean" />
use:
<jsp:useBean id = "DbBean" scope="request" class="testpackage.DbBean" />
Bill

------------------
author of:
 
wood burning stoves
 
subject: Urgent, please help
 
Similar Threads
Trouble connecting to MS Access via ODBC
Errors Running JSP Page
Login Validation In JSP
Drop down box
jdbc value retrieval from a bean and then from a jsp