wood burning stoves 2.0*
The moose likes JSP and the fly likes Jsp got null,false,0 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Jsp got null,false,0" Watch "Jsp got null,false,0" New topic
Author

Jsp got null,false,0

John Hood
Greenhorn

Joined: Aug 06, 2006
Posts: 6
Hi,everyone.It realy bothered me from yesterday.I wrote a java bean called
bookstore to get data from a database and i have made a main methods to test the code.everything works perfectly, but when i move the main methods code to a jsp,damned things happened.i got many null null null 0.0 false 0 null 0 null null null 0.0 false 0 null 0 null null null 0.0 false 0 null 0 null null from the database.I wonder anything wrong with the jsp???!!

here's my code.for the jsp

<%@ page pageEncoding="UTF-8"%>
<%@ page language="java" import="java.util.*" %>
<%@ page language="java" import="java.sql.*" %>
<%@ page language="java" import="exe.*" %>


<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<jsp:useBean id="mybs" class="exe.bookstore" scope="session"/>

<head>
<base href="<%=basePath%>">

<title>My JSP 'booklist.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">

<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>

<body>
<%
try{
for(int i=1;i<=16;i++)
{
bookdetail bd=mybs.getrecordvalue(String.valueOf(i));
out.println(bd.getBookId());
out.println(bd.getTitle());
out.println(bd.getName());
out.println(bd.getPrice());
out.println(bd.isOnSale());
out.println(bd.getYear());
out.println(bd.getDescription());
out.println(bd.getInventory());
}
}catch (Exception ex){}


%>
</body>
</html>

code for javabean

package exe;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Calendar;

import db.SqlLink;


public class bookstore {
ArrayList cargo;
SqlLink mysql;


public bookstore(){
cargo=new ArrayList();
mysql=new SqlLink();
}




public bookdetail getrecordvalue(String id){
ResultSet rs=mysql.executeQuery("select * from books where id="+id);
bookdetail mybd=new bookdetail(rs);
return mybd;

}



public static void main(String[] args) {
bookstore mybs =new bookstore();

try{
for(int i=1;i<=mybs.getrecordscount();i++)
{
bookdetail bd=mybs.getrecordvalue(String.valueOf(i));
System.out.println(bd.getBookId());
System.out.println(bd.getTitle());
System.out.println(bd.getName());
System.out.println(bd.getPrice());
System.out.println(bd.isOnSale());
System.out.println(bd.getYear());
System.out.println(bd.getDescription());
System.out.println(bd.getInventory());

}


}catch(Exception ex){System.out.println("main");}


}


}

another information may be help:

I fina an Exception in another javabean related:
here's code for bookdetail.java

package exe;

import java.sql.*;

public class bookdetail {
private String bookId=null;
private String title=null;
private String name=null;
private float price =0.0F;
private boolean onSale=false;
private int year=0;
private String description =null;
private int inventory=0;

public bookdetail(ResultSet rs)
{
try{
rs.next();
bookId=rs.getString(1);
title=rs.getString(2);
name=rs.getString(3);
price=rs.getFloat(4);
onSale=rs.getBoolean(5);
year=rs.getInt(6);
description=rs.getString(7);
inventory=rs.getInt(8);
}catch(Exception ex){System.out.println("wrong in bookdetail!");}
}
}

p.s: when i directly run the bookstore.java by main methods.it shows the right data from database as
1 dh ag 59.0 true 2004 ch 20 2 hj c 54.0 false 2001 c. 20


I sincere appreciate for any help
John Hood.
[ August 14, 2006: Message edited by: Bear Bibeault ]
nizams uddin
Greenhorn

Joined: Jul 31, 2006
Posts: 15
hi,
you are combining jspscript and jstl together.
either use entire jspscript or jstl and then check.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Javaranch tip:

If you are going to post more than a line or two of your code, wrap that
code in a set of UBB Code tags.
Doing so will help to preserve your code's indenting, making it easier to read.
If it is easier to read, more people will actaully read it and you will
stand a better chance of getting help with your question.
See UseCodeTags for more
help with UBB code tags.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
John Hood
Greenhorn

Joined: Aug 06, 2006
Posts: 6
well,I'll try it
thanks any way.
 
jQuery in Action, 2nd edition
 
subject: Jsp got null,false,0