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 + "\"");
}
%>);
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
<%
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
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()>
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
<%@ 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.
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){
}%>