How to call data from javabean to JSP

Hi all

This is my core java program.

import com.alien.enterpriseRFID.reader.*;

import com.alien.enterpriseRFID.tags.*;

import java.util.*;

publicclass AlienClass1ReaderTest{

/**

* Constructor

*/

public AlienClass1ReaderTest()throws AlienReaderException{

AlienClass1Reader reader =new AlienClass1Reader();

//reader.setConnection("COM1");

// To connect to a networked reader instead, use the following:

reader.setConnection("192.168.0.4", 23);

reader.setUsername("alien");

reader.setPassword("password");

// Open a connection to the reader

reader.open();

// Ask the reader to read tags and print them

Tag tagList[] = reader.getTagList();

if (tagList ==null){

System.out.println("No Tags Found");

}else{

System.out.println("Tag(s) found:");

for (int i=0; i<tagList.length; i++){

Tag tag = tagList[i];

System.out.println("Tag ID:" + tag.getTagID() +

", Antenna:" + tag.getAntenna() +

", Read Counts:" + tag.getRenewCount()

);

}

}

// Close the connection

reader.close();

}

/**

* Main

*/

publicstaticfinalvoid main(String args[]){

try{

AlienClass1ReaderTest test =new AlienClass1ReaderTest();

}catch(AlienReaderException e){

System.out.println("Error: " + e.toString());

}

}

}// End of class AlienClass1ReaderTest

If I run above prpgram we can see following output.

Tag(s) found:

Tag ID:8000 8005 3999 8421, Antenna:0, Read Counts:1

Tag ID:8000 8005 3999 8251, Antenna:0, Read Counts:1

Tag ID:8000 8004 3072 5236, Antenna:0, Read Counts:10

Tag ID:8000 8004 3072 5266, Antenna:0, Read Counts:10

Now I just converted above program in Java Bean so that I can call from JSP.

Following is javabean

package RFIDReaders.ALR9800;

import com.alien.enterpriseRFID.reader.*;

import com.alien.enterpriseRFID.tags.*;

import java.util.*;

publicclass ALR9800Reader{

//Connection Parameters.

private String IP;

private String portStr;

private String log;

private String pass;

//Getter and Setter mthod for TAG

private String tagID;

privateint antenna;

privateint renewCount;

privateint no_of_tag;

AlienClass1Reader reader =new AlienClass1Reader();

/**

* Constructor

*/

public ALR9800Reader(){

}

// Set IP Address of the Reader

publicvoid setIP(String IP){

this.IP = IP;

}

// Set Port # of the Reader

publicvoid setPortStr(String portStr){

this.portStr = portStr;

}

// Set Login of the Reader

publicvoid setLog(String log){

this.log = log;

}

// Set Password of the Reader

publicvoid setPass(String pass){

this.pass = pass;

}

// Connect Alien Reader

publicvoid ConnectALR9800(String IP, String portStr, String log, String pass)throws AlienReaderException{

int port = Integer.parseInt(portStr);

reader.setConnection(IP, port);

reader.setUsername(log);

reader.setPassword(pass);

// Open a connection to the reader

reader.open();

}

// Getter and Setter Method for TagID

publicvoid setTagID(String tagID){

this.tagID = tagID;

}

public String getTagID(){

return tagID;

}

// Getter and Setter Method for Antenna

publicvoid setAntenna(int antenna){

this.antenna = antenna;

}

publicint getAntenna(){

return antenna;

}

//// Getter and Setter Method for Read Count

publicvoid setRenewCount(int renewCount){

this.renewCount = renewCount;

}

publicint getRenewCount(){

return renewCount;

}

publicint getNo_of_tag(){

return no_of_tag;

}

// Getting Tag ID

publicvoid ReaderData()throws AlienReaderException{

// Ask the reader to read tags and print them

Tag tagList[] = reader.getTagList();

for (no_of_tag =0; no_of_tag ><tagList.length; no_of_tag++){

Tag tag = tagList[no_of_tag];

tagID = tag.getTagID();

antenna = tag.getAntenna();

renewCount = tag.getRenewCount();

}

}

// Closing Alien Reader connection

publicvoid CloseALR9800()throws AlienReaderException{

reader.close();

}

}

Now I am using following JSP to call

><%@ page language="java" %>

<%@ page import="java.util.*"%>

<jsp:useBean id="readerALR9800" class="RFIDReaders.ALR9800.ALR9800Reader" scope="session"/>

<jsp:setProperty name="readerALR9800" property="*"/>

<jsp:include page="sendALR9800.jsp" />

<% readerALR9800.ReaderData(); %>

<html>

<head>

</head>

<body>

<hr><table border=1 cellspacing=2 cellpadding=1>

<tr>

<th>S No</th>

<th>TAG ID</th>

<th>Antenna #</th>

<th>READ COUNT</th>

</tr>

<%

// Getting tag data from reader

int n = readerALR9800.getNo_of_tag();

for(int i = 0; i < n; i++){

out.println("<tr><td>"+ (i+1) +"</td>");

out.println("<td>" + readerALR9800.getTagID()+"</td>");

out.println("<td>" + readerALR9800.getAntenna()+"</td>");

out.println("<td>" + readerALR9800.getRenewCount()+"</td>");

out.println("</tr>");

}

%>

</table>

</body>

</html>

when I call from JSP we can see the following output which is only one data repeating four times but it should print four values as I got when I run my core java program.

S No TAG ID Antenna # READ COUNT

1 8000 8004 3072 5266 0 10

2 8000 8004 3072 5266 0 10

3 8000 8004 3072 5266 0 10

4 8000 8004 3072 5266 0 10

Could anybody help me where I am making mistakes?

Thanx

kvijai

[11726 byte] By [kvijaia] at [2007-11-26 18:07:39]
# 1
Dive into the code of ur bean..put some debugging statments in the ban and see where it goes wrong....regardsShanu
mshanua at 2007-7-9 5:39:05 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Thank you very much Shanu

If I use following code (snippet from javabean), then we can see every lines of ouput in Logs directory.

// Ask the reader to read tags and print them

Tag tagList[] = reader.getTagList();

for (no_of_tag =0; no_of_tag <tagList.length; no_of_tag++) {

Tag tag = tagList[no_of_tag];

tagID = tag.getTagID();

antenna = tag.getAntenna();

renewCount = tag.getRenewCount();

[b]System.out.println("Tag ID:" + tagID + ", Antenna:" + antenna + ", Read Counts:" + renewCount);[/b]}

But If i use followig then we can print only one line.

// Ask the reader to read tags and print them

Tag tagList[] = reader.getTagList();

for (no_of_tag =0; no_of_tag ><tagList.length; no_of_tag++) {

Tag tag = tagList[no_of_tag];

tagID = tag.getTagID();

antenna = tag.getAntenna();

renewCount = tag.getRenewCount();

}

[b]System.out.println("Tag ID:" + tagID + ", Antenna:" + antenna + ", Read Counts:" + renewCount);[/b]

Now I am still not able to figure it out how to correct it so that I can print every lines of output.

Thanx

kvijai>

kvijaia at 2007-7-9 5:39:05 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
Hi allCould anybody have a look on this problem. I am still not figure out it why this is happening?Thanxkvijai
kvijaia at 2007-7-9 5:39:05 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

Hi all

Plz have a look at the following part of my javabean code where I think I am making mistakes as [b]tagList is of type Tag [ ] and tag is of type Tag.[/b]

[code][public void ReaderData() throws AlienReaderException{

// Ask the reader to read tags and print them

Tag tagList[] = reader.getTagList();

for (no_of_tag =0; no_of_tag <tagList.length; no_of_tag++) {

Tag tag = tagList[no_of_tag];

tagID = tag.getTagID();

antenna = tag.getAntenna();

renewCount = tag.getRenewCount();

}

} /code]

Thanx

kvijai>

kvijaia at 2007-7-9 5:39:05 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

Hi all

Plz have a look at the following part of my javabean code where I think I am making mistakes as tagList is of type Tag [ ] and tag is of type Tag.

public void ReaderData() throws AlienReaderException{

// Ask the reader to read tags and print them

Tag tagList[] = reader.getTagList();

for (no_of_tag =0; no_of_tag <tagList.length; no_of_tag++) {

Tag tag = tagList[no_of_tag];

tagID = tag.getTagID();

antenna = tag.getAntenna();

renewCount = tag.getRenewCount();

}

}

Thanx

kvijai>

kvijaia at 2007-7-9 5:39:05 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...