Storing vales on clientside

Hi, Can u tell me how to store the values that are retrieved from the serverside on the clientsideFor ex i retrieved values from database using JSP and i want to store them in a Java script array so that they can be used afterwards for clientside working.Thanks in
[300 byte] By [subhakarkatamaneni@yahoo.co.ina] at [2007-10-2 12:59:37]
# 1
Not sure if this will help,I never used AJAX, but I think this would help you.
javagalaxy.coma at 2007-7-13 10:18:52 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

simple tricks will do

for string

var sampleString = "<%=javastring%>";

for array

var sampleArray= new Array(

<%out.println("\""+javaArray[0]+"\"");

for(int i = 1; i < javaArray.length(); i++) {

out.println(", \"" + javaArray + "\"");

}

%>);

jgalacambraa at 2007-7-13 10:18:52 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

I have almost same problem. Iam trying to store some data and read some data from the clients computer. I dontknow how to do this.

I actually tried using "C:/filename.txt".

however when i run my application from a clients computer it still stores the file in the C:/ drive of the computer that i have tomcat running. i want it to store in the cleints computer itself.

I know that we can use the following for storing in webapps directory etc on server

application.getRealPath("/") + "filename.txt";

Do we have something like this to get the path of the clients computer.

thanks in advance

rocky

rockyreddy2100a at 2007-7-13 10:18:52 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
why do you need the path?
jgalacambraa at 2007-7-13 10:18:52 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
Hi rocky,Exactly that was not my problem, My problem is to bring values from the server-side ie from database and store them on clientside using javascript arrays
subhakarkatamaneni@yahoo.co. at 2007-7-13 10:18:52 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
please read my reply on how to store them
jgalacambraa at 2007-7-13 10:18:52 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7
Thank u i read that replyI am able to store them in the array but iam unable to display them on the browser.
subhakarkatamaneni@yahoo.co. at 2007-7-13 10:18:52 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8
can you post the your code on how you are dispalying it?
jgalacambraa at 2007-7-13 10:18:52 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 9
i dont need the path.how do i save it in the clients C:/ drive thanks for ur replyrocky
rockyreddy2100a at 2007-7-13 10:18:52 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 10
you can't write to anybody's computer.. so what you are trying to do might be impossible
jgalacambraa at 2007-7-13 10:18:52 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 11

<%

Class.forName("com.mysql.jdbc.Driver");

Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/andhravaani","root","root");

Statement st = con.createStatement();

ResultSet rs = st.executeQuery("select * from andhravaani");

%>

<script language="javascript" type="text/javascript">

var a = new Array[];

<% int i=0;

while(rs.next())

{

%>

a[<%=i%>] = "<%=rs.getString(1)%>";

<%

i++;

}

%>

for(var i=0;i<10;i++)

{

document.write(a);

}

</script>

This was the code iam able to see in the code that the values retrieved from the database are stored in the array but iam unable to display them can u please help me out

Thanks for ur help

subhakarkatamaneni@yahoo.co. at 2007-7-13 10:18:52 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 12
can i atleast read from the clients computerrocky
rockyreddy2100a at 2007-7-13 10:18:52 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 13
Hi rocky,Can u create a seperate thread and ask queries rather than using mine.
subhakarkatamaneni@yahoo.co. at 2007-7-13 10:18:52 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 14

i modify your code tell me if thee will be errors

<%

Class.forName("com.mysql.jdbc.Driver");

Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/andhravaani","root","root");

Statement st = con.createStatement();

ResultSet rs = st.executeQuery("select * from andhravaani");

%>

<script language="javascript" type="text/javascript">

var a = new Array[];

function setValues(){

<% int i=0;

while(rs.next())

{

%>

a[<%=i%>] = "<%=rs.getString(1)%>";

<%

i++;

}

%>

for(var i=0;i<10;i++)

{

document.write(a);

}

}

</script>

on the body tag

<body onload=setValues()>

jgalacambraa at 2007-7-13 10:18:52 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 15

to rocky i think you can't because in http the client computer have the only way to make connections to the server. the server cannot create a connection to the clients computer so it cannot access whats inside the clients computer unless you have some programs(other than web application maybe desktop applications) installed on the computer that the server can communicate with the clients computer

jgalacambraa at 2007-7-20 21:43:34 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 16
I tried itnothing has changed still the retrieved values cannot be displayed, but until now i was getting only 1 runtime error but after modifying i got 2 of them.
subhakarkatamaneni@yahoo.co. at 2007-7-20 21:43:34 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 17
can you post the whole code of your jsp and the errors
jgalacambraa at 2007-7-20 21:43:34 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 18

<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<body>

<%

Class.forName("com.mysql.jdbc.Driver");

Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/andhravaani","root","root");

Statement st = con.createStatement();

ResultSet rs = st.executeQuery("select * from andhravaani");

%>

<script language="javascript" type="text/javascript">

var a = new Array[];

<% int i=0;

while(rs.next())

{

%>

a[<%=i%>] = "<%=rs.getString(1)%>";

<%

i++;

}

%>

for(var i=0;i<10;i++)

{

document.write(a);

}

</script>

<table width="620" height="360" border="1">

<tr>

<th width="162" scope="col"><table width="162" height="351" border="1">

<tr>

<th width="160" scope="col">Todays Special</th>

</tr>

<tr>

<th scope="row">Tollywood</th>

</tr>

<tr>

<th scope="row">Audio</th>

</tr>

<tr>

<th scope="row">Entertainment</th>

</tr>

<tr>

<th scope="row">Kids Special</th>

</tr>

</table></th>

<th width="266" scope="col">

<table width="272" height="351" border="1">

<tr>

<th scope="col">

</th>

</tr>

</table></th>

<th width="162" scope="col"><table width="162" height="351" border="1">

<tr>

<th scope="col">Andhravaani Music</th>

</tr>

<tr>

<th scope="row">Specials</th>

</tr>

<tr>

<th scope="row">Downloads</th>

</tr>

<tr>

<th scope="row">Ladies Special </th>

</tr>

<tr>

<th scope="row">Opinion Poll </th>

</tr>

</table></th></tr>

</table>

</body>

</html>

This was my entire code i has to display the retrived values in the middle block and regarding errors it was not giving any description it was simply giving an error occered at line number in an alert box.

Thank u very much for helping me.

subhakarkatamaneni@yahoo.co. at 2007-7-20 21:43:34 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 19
dude, sorry abt that.I appreciate all those replies.good luck..it's all ursrocky
rockyreddy2100a at 2007-7-20 21:43:34 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 20
thanks bro.I appreciate it.rocky
rockyreddy2100a at 2007-7-20 21:43:34 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 21

here's what i've got so far.. i make a comment on you connection to your database. i didn't remove what i make to connect to my database in order for you to have a guide on how to do a db connection.. i alaso modify some code in your jsp too many to enumerate try this one i have tested it.. its working

<%@ page contentType="text/html; charset=iso-8859-1" import="java.sql.*"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%

/*

Class.forName("com.mysql.jdbc.Driver");

Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/andhravaani","root","root");

Statement st = con.createStatement();

ResultSet rs = st.executeQuery("select * from andhravaani");*/

try{

DriverManager.registerDriver(new oracle.jdbc.OracleDriver());

Connection con = DriverManager.getConnection("jdbc:oracle:thin:@172.16.167.216:1521:eoffice","eadmin","i5up0w3r5");

Statement st = con.createStatement();

ResultSet rs = st.executeQuery("select item_no from trans_medical_codes");

%>

<html>

<head>

<title></title>

</head>

<body >

<script language="javascript">

var a = new Array();

<% int i=0;

while(rs.next())

{

%>

a[<%=i%>] = "<%=rs.getString(1)%>";

<%

i++;

}

%>

function display(){

for(var i=0;i<10;i++)

{

document.write(a);

}

}

display()

</script>

<table width="620" height="360" border="1">

<tr>

<th width="162" scope="col"><table width="162" height="351" border="1">

<tr>

<th width="160" scope="col">Todays Special</th>

</tr>

<tr>

<th scope="row">Tollywood</th>

</tr>

<tr>

<th scope="row">Audio</th>

</tr>

<tr>

<th scope="row">Entertainment</th>

</tr>

<tr>

<th scope="row">Kids Special</th>

</tr>

</table></th>

<th width="266" scope="col">

<table width="272" height="351" border="1">

<tr>

<th scope="col">

</th>

</tr>

</table></th>

<th width="162" scope="col"><table width="162" height="351" border="1">

<tr>

<th scope="col">Andhravaani Music</th>

</tr>

<tr>

<th scope="row">Specials</th>

</tr>

<tr>

<th scope="row">Downloads</th>

</tr>

<tr>

<th scope="row">Ladies Special </th>

</tr>

<tr>

<th scope="row">Opinion Poll </th>

</tr>

</table></th></tr>

</table>

</body>

</html>

<%con.close();

}catch(Exception e){

}%>

jgalacambraa at 2007-7-20 21:43:34 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 22
Thank u very much for ur help i too got the output with u helpOnce again thank u very much.
subhakarkatamaneni@yahoo.co. at 2007-7-20 21:43:34 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 23
np cheers:)
jgalacambraa at 2007-7-20 21:43:34 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...