How to do it in JSP

Hi all

Just calling only one method I get the data as follows.

E004010001E1B520 E004010001E1B520 E004010001E1B520 E004010001E1B643 E004010001E1B678 E004010001E1B678

What I wanna do it that this value(E004010001E1B520) appears three times, I wanna print it only once and count the number of appearance and same thing with other values(E004010001E1B643) and(E004010001E1B678).

I mean I wanna print in a table it as follows

Sl. NoTAGID COUNT

1E004010001E1B5203

2E004010001E1B6431

3E004010001E1B6782

Thanx

kvijai

[578 byte] By [kvijaia] at [2007-11-26 15:11:50]
# 1
wht is u'r datataype?
rengaraja at 2007-7-8 9:02:52 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
r u fetchng the value from Database ?
rengaraja at 2007-7-8 9:02:52 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
The datatype is String.I am getting this data from RFID reader, when I send a command to this reader. Thanxkvijai
kvijaia at 2007-7-8 9:02:52 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
Hi allI didn't get any reply to resolve my problem yet. Is it to difficult to do it OR is it not right forum to ask it?Thanxkvijai
kvijaia at 2007-7-8 9:02:52 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

@kvijai

Its more of a Java specified Problem

you may have to design an algorithm & write a method or a Util class to analyse this Input

Say i am passing a String to a method called report(String RfConsole)

where as per your requirement

RfConsole = "E004010001E1B520 E004010001E1B520 E004010001E1B520 E004010001E1B643 E004010001E1B678 E004010001E1B678";

in the specfied pattern i'm observing the following onces

E004010001E1B520 --> String.length() = 16

E004010001E1B643 > String.length() = 16

E004010001E1B678 > String.length() = 16

so as per it i am trying to a condition or a regular expression in the following way..

RF > <16_CHARECTERED_STRING> + "SINGLE_SPACE " + RF

Letus extract all 16 charectered strings one by one and place them in a List<String>.

Let us now sort the list

which groups similar values consequtively to say something like

E004010001E1B520 --> 1

E004010001E1B520 > 2

E004010001E1B520 > 3

E004010001E1B643 > 4

E004010001E1B678 > 5

E004010001E1B678 > 6

let us now write a logic where we are creating a Map<String,Integer>

int count = 1;

Map.put(List.get(1),count);

for(int i=0 ; i <List.size();i++ ){

if(List.get(i).equals(List.get(i+1)) == true ){

count = count + 1;

Map.put(List.get(i),count);

} else{

count = 1;

Map.put(List.get(i),count);

}

}

After all this all you have to do is to build a Table Representation from created Map.>

RahulSharnaa at 2007-7-8 9:02:52 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
Hi RahulThank you very much.I need little bit more clarification, sorry for this. How to apply this algo on the getting data and extract & put them in List.Thanx kvijai
kvijaia at 2007-7-8 9:02:52 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7

Alright here is an example class for you to convert the input....

Watch out for saveRfConsoleIp(String InputString) which returns a Sorted List by which you can apply my earlier algorithm....

And getRfIpMap(List<String> list) returns the final Map / Table which you are refering to

its almost a complete solution for the approach which i was refering to..... (Readily executable)

CAUTION:However,this approach can suffer with high Space Complexity if Input provided is Too large....

NOTE: Assumption made here (is) / (are some) spaces between each RFID.for example "E004010001E1B520 E004010001E1B520 E004010001E1B520 E004010001E1B643".

import java.util.Collections;

import java.util.List;

import java.util.ArrayList;

import java.util.Map;

import java.util.TreeMap;

import java.util.StringTokenizer;

/**

* Author : rahul.a

*/

class SampleRfInputDemo{

//Sample input

static String in = "E004010001E1B520 E004010001E1B520 E004010001E1B520 E004010001E1B643 E004010001E1B678 E004010001E1B678 E004010001E1B521 E004010001E1B520 E004010001E1B678";

/* The following method resolves the input and converts it into a Sorted List */

public List<String> saveRfConsoleIp(String InputString) {

ArrayList<String> SampleList = new ArrayList<String>();

StringTokenizer st = new StringTokenizer (InputString," ");

while(st.hasMoreTokens()){

String value = st.nextToken();

SampleList.add(value.trim());

}

Collections.sort(SampleList);

return(SampleList);

}

/* Final Map Which arranges data in format

*E004010001E1B520 = <Number_of_occurances>

*/

public Map<String,Integer> getRfIpMap(List<String> list){

TreeMap<String,Integer> map = new TreeMap<String,Integer>();

int count = 1;

if(list.size() > 0 && list != null){

map.put(list.get(0),count);

for(int i=0;i<list.size() - 1;i++){

if(list.get(i).equals(list.get(i+1)) == true)

count = count + 1;

else

count = 1;

map.put(list.get(i+1),count);

}

}

return(map);

}

public static void main(String s[]){

SampleRfInputDemo sample = new SampleRfInputDemo();

System.out.println( sample.getRfIpMap(sample.saveRfConsoleIp(in.trim())) );

}

}

Hope This Helps

REGARDS,

RaHuL>

RahulSharnaa at 2007-7-8 9:02:52 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8

Thanx Rahul

Exactly same thing i was expecting, but my problem is how to print this data in a table on my JSP page. One more thing finally i wanna count all the occurences together, from following output i wanna print total count=9. Sorry for this i am new to this topic.

{E004010001E1B520=4, E004010001E1B521=1, E004010001E1B643=1, E004010001E1B678=3}

Thanx

kvijai

kvijaia at 2007-7-8 9:02:52 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 9

well you have evrything with now, you did find how many occurances where there too.... in order to display the result using JSP use the following class as a bean & in order to find the total number all you can do is to sum everything up.

place SampleRfInputDemo.class at <Your_web_appln/web-inf/classes/com/RfDetect path and to the above code add an extra line right at the top pckage com.RfDetect;

i.e

package com.RfDetect;

import java.util.Collections;

import java.util.List;

import java.util.ArrayList;

import java.util.Map;

import java.util.TreeMap;

import java.util.StringTokenizer;

/**

* Author : rahul.a

*/

class SampleRfInputDemo{

//Sample input

static String in = "E004010001E1B520 E004010001E1B520 E004010001E1B520 E004010001E1B643 E004010001E1B678 E004010001E1B678 E004010001E1B521 E004010001E1B520 E004010001E1B678";

/* The following method resolves the input and converts it into a Sorted List */

public List><String> saveRfConsoleIp(String InputString) {

ArrayList<String> SampleList = new ArrayList<String>();

StringTokenizer st = new StringTokenizer (InputString," ");

while(st.hasMoreTokens()){

String value = st.nextToken();

SampleList.add(value.trim());

}

Collections.sort(SampleList);

return(SampleList);

}

/* Final Map Which arranges data in format

*E004010001E1B520 = <Number_of_occurances>

*/

public Map<String,Integer> getRfIpMap(List<String> list){

TreeMap<String,Integer> map = new TreeMap<String,Integer>();

int count = 1;

if(list.size() > 0 && list != null){

map.put(list.get(0),count);

for(int i=0;i<list.size() - 1;i++){

if(list.get(i).equals(list.get(i+1)) == true)

count = count + 1;

else

count = 1;

map.put(list.get(i+1),count);

}

}

return(map);

}

}

and compile the file to genarate a new SampleRfInputDemo.class file there and then try the code mentioned below...

><%@page language="java" import="java.util.Map,java.util.Set"%>

<jsp:usebean id="sample" class="com.RfDetect.SampleRfInputDemo" />

<%

Map<String,Integer> OutPut = sample.getRfIpMap(sample.saveRfConsoleIp("E004010001E1B520 E004010001E1B520 E004010001E1B520 E004010001E1B643 E004010001E1B678 E004010001E1B678 E004010001E1B521 E004010001E1B520 E004010001E1B678"));

int SIZE = OutPut.size();

%>

<html>

<head>

<title>Rf Indication</title>

</head>

<body>

<table border="1">

<tr>

<th>SNO</th>

<th>RFID</th>

<th>COUNT</th>

</tr>

<%

int totcount = 0;

Set key = OutPut.keySet();

Object keys[] = key.toArray();

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

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

out.println("<td>"+keys[i]+"</td>");

out.println("<td>"+OutPut.get(keys[i])+"</td>");

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

Integer inc = (Integer) OutPut.get(keys[i]);

totcount = totcount + inc.intValue();

}

%>

</table>

<%

out.println("The total count is "+totcount);

%>

</body>

</html>

However,it would be lot better if we can use JSTL instead of scriptlets for better readablity.

Hope this helps

REGARDS,

RaHuL

RahulSharnaa at 2007-7-8 9:02:52 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 10

Hi Rahul

Actually the data I am getting is real time, its always changing . I was able to run successfully your program. But If I modify this code to my code there are many problems. Anyway I am giving you following JSP page which send the command to reader and get the raw datas through javabean.

<jsp:useBean id="conn" class="RFIDReaders.RS232Reader.SerialReader" scope="session"/>

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

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

<%

conn.setWriteString("t \r");

conn.SerialWrite();

%>

<%

String Data = conn.getData();

out.println(Data);

%>

As I call this page, the method [conn.setWriteString("t \r");] sends the command to the reader and method [conn.getData] gives the raw data. This same raw datas I wanna display in the table.

Thanx

kvijai

kvijaia at 2007-7-8 9:02:52 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 11

>But If I modify this code to my code there are many >problems. Anyway I am giving you following JSP >page which send the command to reader and get >the raw datas through javabean.

Wat are those ? Please metion

However as refering to your real time data acqusition process i think you have to do something similar to the one below (After following the procedure which i asked you to follow as per my previous post)

<%@page language="java" import="java.util.Map,java.util.Set"%>

<jsp:usebean id="sample" class="com.RfDetect.SampleRfInputDemo" />

<jsp:useBean id="conn" class="RFIDReaders.RS232Reader.SerialReader" scope="session"/>

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

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

<%

conn.setWriteString("t \r");

conn.SerialWrite();

%>

<%

String Data = conn.getData();

Map<String,Integer> OutPut = sample.getRfIpMap(sample.saveRfConsoleIp(Data));

int SIZE = OutPut.size();

%>

<html>

<head>

<title>Rf Indication</title>

</head>

<body>

<table border="1">

<tr>

<th>SNO</th>

<th>RFID</th>

<th>COUNT</th>

</tr>

<%

int totcount = 0;

Set key = OutPut.keySet();

Object keys[] = key.toArray();

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

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

out.println("<td>"+keys[i]+"</td>");

out.println("<td>"+OutPut.get(keys[i])+"</td>");

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

Integer inc = (Integer) OutPut.get(keys[i]);

totcount = totcount + inc.intValue();

}

%>

</table>

<%

out.println("The total count is "+totcount);

%>

</body>

</html>

RahulSharnaa at 2007-7-8 9:02:52 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 12

Thanx Rahul

/Sample input

static String in = "E004010001E1B520 E004010001E1B520 E004010001E1B520 E004010001E1B643 E004010001E1B678 E004010001E1B678 E004010001E1B521 E004010001E1B520 E004010001E1B678";

I think the above String in javabean SampleRfInputDemo is creating problem. Because this String values come out from conn.getData().

Thanx

kvijai

kvijaia at 2007-7-8 9:02:52 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 13
makeuse my last post and try it out i'm sure u can resolve it.....
RahulSharnaa at 2007-7-8 9:02:52 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 14
Hi RahulFollowing is the output for calling the real time data (String Data=conn.getData)SNORFIDCOUNT 1E004010001E1B520 E004010001E1B520 E004010001E1B520 E004010001E1B5201 The total count is 1
kvijaia at 2007-7-8 9:02:52 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 15

Letz try to trim the String which you are getting as an input from RfBean say something like

String Data = conn.getData().trim();

and in the utility(SampleRfInputDemo) class replace

StringTokenizer st = new StringTokenizer (InputString," ");

with

StringTokenizer st = new StringTokenizer (InputString," \t");

If doesn't work out i think we are back to square 1

E004010001E1B520 E004010001E1B520 E004010001E1B520 E004010001E1B520

Just define the grammer for the above input data

is it something like ?

<GRAMMER> > <RFID_STRING> + <SPACE_OR_SPACE>+<GRAMMER>

<GRAMMER> > <RFID_STRING>

I think i'm running out patience.My Minimal requirement is that you define the data which your are getting from a Bean properly.

If you are sure that you can resolve it into a Regular Expression or Specific Pattern Plz comeback and post ur queries.......

:)

RahulSharnaa at 2007-7-8 9:02:54 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 16

Hi Rahul

Thank you very much for your patience

Now finally i got it worked, I just changed the following code

StringTokenizer st = new StringTokenizer (InputString," ");

to this code in javabean

StringTokenizer st = new StringTokenizer (InputString);

Once again thank you very much

kvijai

kvijaia at 2007-7-8 9:02:54 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 17

Hi

Now days I'm dealing with the different RFID readers, so i think its better to continue this thread.

In this case my output is as follows:

01 REF04020001BBAFA79D4B 01 REF04020001BBAFA79D4B 01 R0000000000000000CEC1 01 R0000000000000000CEC1 01 REF04020001BB89CDFCE7 01 P

And I wanna it in the following table format.

SL NoAnt No TagID Count

101REF04020001BBAFA79D4B2

201R0000000000000000CEC12

301REF04020001BB89CDFCE71

I think in this case I need to remove letter P which appears in the last.

Thanks

kvijai

kvijaia at 2007-7-8 9:02:54 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 18
Hi Rahul.Plz have a look on the just previous post. I really stuck once again here. I thought this case will be more easy after completing the first RFID reader.Thanxkvijai
kvijaia at 2007-7-8 9:02:54 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...