rac13
asked on
Read from Database using Javascript?
Hi,
is it possible for the javascript to call and read from a database from a server and load it into the html? If possible, where can I find the sample code?
Thanks
is it possible for the javascript to call and read from a database from a server and load it into the html? If possible, where can I find the sample code?
Thanks
How to do that in ASP?
http://www.asp101.com/samples/database.asp
When using ASP, you would need a web server like PWS or IIS.
When using ColdFusion, you would need a web server like IIS or PWS. Apart from that, you would also need ColdFusion server.
hongjun
http://www.asp101.com/samples/database.asp
When using ASP, you would need a web server like PWS or IIS.
When using ColdFusion, you would need a web server like IIS or PWS. Apart from that, you would also need ColdFusion server.
hongjun
ASKER
Wat abot vbscript then?
You cannot do that in client side. Must do it in server side. Use ASP if you are familiar with VBScript since a server codes can be in VBScript.
hongjun
hongjun
ASKER
I had this constrait that my page had to be in a html, is there anyway that I can call a servlet and display it in my html?
I don't think that's possible
hongjun
hongjun
Actually I do believe there is a way to access a database without using a serverside language. There are several options, but you can't do it with pure ECMA compliant JavaScript.
Depending how elegant or clumsy you want to do it, the browsers versions it must be compatible with, and how much control you have over your DB server, there are three options:
1) Put an applet in a hidden frame, and have that look up the database values and make them available to your html in another frame. This should work in any proper java enabled browser.
This will work with pretty much any normal database.
2) Put an applet in the actual page that you want to show the data, have it look up the data, and modify the page on the fly, with w3cs set of DOM javascript functions, and the "innerHTML" property, which will work in both Netscape 6 and above, and Explorer 5.0 and above.
This will work with pretty much any normal database.
3) Put a flash element on your page, and have that show your data instead. Flash 5 can create XMLSockets that connect to a server and communicate XML messages back and forth. If you can make sure your database server speaks XML, then you can get the data like that. Flash CAN actually communicate the data to JavaScript as well, but that's getting a bit to kludgy.
Tell me if you are interested in any of these solutions, in which case I will answer the one you want. You will have to up the number of points though - the descriptions will take some time.
Depending how elegant or clumsy you want to do it, the browsers versions it must be compatible with, and how much control you have over your DB server, there are three options:
1) Put an applet in a hidden frame, and have that look up the database values and make them available to your html in another frame. This should work in any proper java enabled browser.
This will work with pretty much any normal database.
2) Put an applet in the actual page that you want to show the data, have it look up the data, and modify the page on the fly, with w3cs set of DOM javascript functions, and the "innerHTML" property, which will work in both Netscape 6 and above, and Explorer 5.0 and above.
This will work with pretty much any normal database.
3) Put a flash element on your page, and have that show your data instead. Flash 5 can create XMLSockets that connect to a server and communicate XML messages back and forth. If you can make sure your database server speaks XML, then you can get the data like that. Flash CAN actually communicate the data to JavaScript as well, but that's getting a bit to kludgy.
Tell me if you are interested in any of these solutions, in which case I will answer the one you want. You will have to up the number of points though - the descriptions will take some time.
ASKER
I'm quite interested in the applets one. I did try before, but my applets are not loading...
Start a new question for more points called "how do I use applets to lookup data in a database, and present them in HTML.
Which applets one are you interested in?
Which applets one are you interested in?
I should probably ask you what your level of Java expertise is, before embarking on an explanation of this scheme.
What is your level of java expertise?
What is your level of java expertise?
ASKER
This method:
2) Put an applet in the actual page that you want to show the data, have it look up the data, and modify
the page on the fly, with w3cs set of DOM javascript functions, and the "innerHTML" property, which
will work in both Netscape 6 and above, and Explorer 5.0 and above.
This will work with pretty much any normal database.
If the solution works, I'll increased the points. Don't worry, you'll get ur expert points.
2) Put an applet in the actual page that you want to show the data, have it look up the data, and modify
the page on the fly, with w3cs set of DOM javascript functions, and the "innerHTML" property, which
will work in both Netscape 6 and above, and Explorer 5.0 and above.
This will work with pretty much any normal database.
If the solution works, I'll increased the points. Don't worry, you'll get ur expert points.
ASKER
I'm a beginner.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Depending on how much of a beginner you are with java, you might want to take a look at the excellent :
http://java.sun.com/docs/books/tutorial/
ASKER
I can't load my page. It said that the class is not found. I haven't get to the javascript yet.
ASKER
It is working well in the Visual Cafe, but once I cab in and load onto my html page..
It said that it can't load.
It said that it can't load.
Are you using applet html that visual cafe is generating?
It sounds like you are just leaving out codebase="..." from your applet tag?
It sounds like you are just leaving out codebase="..." from your applet tag?
May I ask why you you are so set on making it client side ?
It really is much easier doing it serverside?
It's a much bigger challenge to do it clientside though :)
It really is much easier doing it serverside?
It's a much bigger challenge to do it clientside though :)
ASKER
This is my HTML:
<HTML>
<HEAD>
<TITLE>QUEQPPRICEPage</TIT LE>
</HEAD>
<body bgcolor="#C0C0C0" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
<center><table><tr><td bgcolor="#CC0000" align="center" valign="middle">
<font face="Arial, Helvetica, sans-serif" size="5" color="#FFFFFF">
<b><i> Corporate Customers' Equipment Pricing Enquiry </i></b></font>
</td</tr></table></center>
<table><tr><td><font size="+1"><b>Please Select a Manufacturer: </b></td>
<td>
<APPLET CODE="QUEQPPRICE" Name="MFGList" WIDTH=200 HEIGHT=200>
<param name="namespace" value="Eqpt Price">
<param name=useslibrary value="Eqpt Price (Dev)">
<param name=useslibrarycodebase value="/NetDynamics/applet s/eqptpric e.cab">
<param name=useslibraryversion value="0,0,0,2">
</APPLET>
</td></tr>
<tr><td><center><input type="submit" value="Fetch Details"></center></td></t r>
</table>
</BODY>
</HTML>
I'm not sure wat this application is, but it seems that they only can have one HTML file. If I have the choice I would do otherwise too.
<HTML>
<HEAD>
<TITLE>QUEQPPRICEPage</TIT
</HEAD>
<body bgcolor="#C0C0C0" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
<center><table><tr><td bgcolor="#CC0000" align="center" valign="middle">
<font face="Arial, Helvetica, sans-serif" size="5" color="#FFFFFF">
<b><i> Corporate Customers' Equipment Pricing Enquiry </i></b></font>
</td</tr></table></center>
<table><tr><td><font size="+1"><b>Please Select a Manufacturer: </b></td>
<td>
<APPLET CODE="QUEQPPRICE" Name="MFGList" WIDTH=200 HEIGHT=200>
<param name="namespace" value="Eqpt Price">
<param name=useslibrary value="Eqpt Price (Dev)">
<param name=useslibrarycodebase value="/NetDynamics/applet
<param name=useslibraryversion value="0,0,0,2">
</APPLET>
</td></tr>
<tr><td><center><input type="submit" value="Fetch Details"></center></td></t
</table>
</BODY>
</HTML>
I'm not sure wat this application is, but it seems that they only can have one HTML file. If I have the choice I would do otherwise too.
That's makes no sense to me out of context. You'll have to read up on the applet tag. Your applet is using some kind of class that it cant find, I think. That's usually due to the applettag.
You might try and stick a codebase="." into the applet tag and see if that solves it.
You might try and stick a codebase="." into the applet tag and see if that solves it.
ASKER
They are using Net Dynmaic to do this application. The html page is created by it. Then I have to modify the page to display wat I want.
I don't get wat u mean.
I don't get wat u mean.
Change :
<APPLET CODE="QUEQPPRICE" Name="MFGList" WIDTH=200 HEIGHT=200>
to :
<APPLET CODE="QUEQPPRICE" Name="MFGList" WIDTH=200 HEIGHT=200 codebase=".">
I can't explain it any clearer. Go to http://java.sun.com and read about the applet tag under "documentation".
<APPLET CODE="QUEQPPRICE" Name="MFGList" WIDTH=200 HEIGHT=200>
to :
<APPLET CODE="QUEQPPRICE" Name="MFGList" WIDTH=200 HEIGHT=200 codebase=".">
I can't explain it any clearer. Go to http://java.sun.com and read about the applet tag under "documentation".
ASKER
I had tried your suggestion but it won't work. I had also check the .cab file and all the class that I need are in there.
I'm fresh outta options then.
ASKER
How should I get the data from the applet using Javascript?
<HTML>
<HEAD>
<TITLE>QUEQPPRICEPage</TIT LE>
<script language = "JavaScript">
function getMFG()
{
var MFG = this.MFGList.cbMFG.getSele ctedItem() ;
alert("The selected Item: " + MFG);
}
</script>
</HEAD>
<body bgcolor="#C0C0C0" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
<form name="QUCORPPLANPage" method="POST" ACTION="" onSubmit="getMFG()">
<center><table><tr><td bgcolor="#CC0000" align="center" valign="middle">
<font face="Arial, Helvetica, sans-serif" size="5" color="#FFFFFF">
<b><i> Corporate Customers' Equipment Pricing Enquiry </i></b></font>
</td</tr></table></center>
<br><br>
<table><tr><td><font size="+1"><b>Please Select a Manufacturer: </b></td>
<td>
<APPLET ARCHIVE="/NetDynamics/appl ets/etpric e.jar" CODE=EqutPrice NAME
="MFGList" WIDTH=200 HEIGHT=50>
</APPLET>
</td></tr>
<tr><td><center><input type="submit" value="Fetch Details"></center></td></t r>
</table>
</body>
</html>
The Javascript don't work.
<HTML>
<HEAD>
<TITLE>QUEQPPRICEPage</TIT
<script language = "JavaScript">
function getMFG()
{
var MFG = this.MFGList.cbMFG.getSele
alert("The selected Item: " + MFG);
}
</script>
</HEAD>
<body bgcolor="#C0C0C0" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
<form name="QUCORPPLANPage" method="POST" ACTION="" onSubmit="getMFG()">
<center><table><tr><td bgcolor="#CC0000" align="center" valign="middle">
<font face="Arial, Helvetica, sans-serif" size="5" color="#FFFFFF">
<b><i> Corporate Customers' Equipment Pricing Enquiry </i></b></font>
</td</tr></table></center>
<br><br>
<table><tr><td><font size="+1"><b>Please Select a Manufacturer: </b></td>
<td>
<APPLET ARCHIVE="/NetDynamics/appl
="MFGList" WIDTH=200 HEIGHT=50>
</APPLET>
</td></tr>
<tr><td><center><input type="submit" value="Fetch Details"></center></td></t
</table>
</body>
</html>
The Javascript don't work.
how doesn't it work?
Do you have the proper objects and methods visible to javascript?
what kind of error do you get?
Do you have the proper objects and methods visible to javascript?
what kind of error do you get?
ASKER
Run time error:
'this.MFGList.cbMFG' is not an object.
'this.MFGList.cbMFG' is not an object.
ASKER
This is my new HTML and it is working:
<HTML>
<HEAD>
<TITLE>QUEQPPRICEPage</TIT LE>
</HEAD>
<body bgcolor="#C0C0C0" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
<form name="QUCORPPLANPage" method="POST" ACTION="http://localhost/servlet/CorpEqptEnquir
yServlet_Action" onSubmit="getMFG()">
<center><table><tr><td bgcolor="#CC0000" align="center" valign="middle">
<font face="Arial, Helvetica, sans-serif" size="5" color="#FFFFFF">
<b><i> Corporate Customers' Equipment Pricing Enquiry </i></b></font>
</td</tr></table></center>
<br><br>
<table><tr><td><font size="+1"><b>Please Select a Manufacturer: </b></td>
<td>
<APPLET ARCHIVE="/NetDynamics/appl ets/etpric e.jar" CODE=com.singtel.EasiQUEQP PRICE.Equt Price NAME
="MFGList" WIDTH=200 HEIGHT=50>
</APPLET>
</td></tr>
<tr><td><center><input type="submit" value="Fetch Details"></center></td></t r>
</table>
<script language = "JavaScript">
function getMFG()
{
document.write('<input type="hidden" name="MFG" value="' + document.MFGList.getListIt em() + '">'
);
}
</script>
</form>
</BODY>
</HTML>
But I am unable to get my servlet working.
It gets the error as below:
500 Internal Server Error
/servlet/CorpEqptEnquirySe rvlet_Acti on:
null
java.lang.NullPointerExcep tion
at CorpEqptEnquiryServlet_Act ion.doPost (CorpEqptE nquiryServ let_Action .java:36)
at javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 772)
at javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 865)
at allaire.jrun.servlet.JRunS E.service( JRunSE.jav a:1013)
at allaire.jrun.servlet.JRunS E.runServl et(JRunSE. java:925)
at allaire.jrun.servlet.JRunN amedDispat cher.forwa rd(JRunNam edDispatch er.java:34 )
at allaire.jrun.servlet.Invok er.service (Invoker.j ava:84)
at allaire.jrun.servlet.JRunS E.service( JRunSE.jav a:1013)
at allaire.jrun.servlet.JRunS E.runServl et(JRunSE. java:925)
at allaire.jrun.servlet.JRunR equestDisp atcher.for ward(JRunR equestDisp atcher.jav a:88)
at allaire.jrun.servlet.JRunS E.service( JRunSE.jav a:1131)
at allaire.jrun.servlet.JvmCo ntext.disp atch(JvmCo ntext.java :330)
at allaire.jrun.http.WebEndpo int.run(We bEndpoint. java:107)
at allaire.jrun.ThreadPool.ru n(ThreadPo ol.java:27 2)
at allaire.jrun.WorkerThread. run(Worker Thread.jav a:75)
But when I got the Javascript out and manually put in the hidden value. It works.
<HTML>
<HEAD>
<TITLE>QUEQPPRICEPage</TIT
</HEAD>
<body bgcolor="#C0C0C0" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
<form name="QUCORPPLANPage" method="POST" ACTION="http://localhost/servlet/CorpEqptEnquir
yServlet_Action" onSubmit="getMFG()">
<center><table><tr><td bgcolor="#CC0000" align="center" valign="middle">
<font face="Arial, Helvetica, sans-serif" size="5" color="#FFFFFF">
<b><i> Corporate Customers' Equipment Pricing Enquiry </i></b></font>
</td</tr></table></center>
<br><br>
<table><tr><td><font size="+1"><b>Please Select a Manufacturer: </b></td>
<td>
<APPLET ARCHIVE="/NetDynamics/appl
="MFGList" WIDTH=200 HEIGHT=50>
</APPLET>
</td></tr>
<tr><td><center><input type="submit" value="Fetch Details"></center></td></t
</table>
<script language = "JavaScript">
function getMFG()
{
document.write('<input type="hidden" name="MFG" value="' + document.MFGList.getListIt
);
}
</script>
</form>
</BODY>
</HTML>
But I am unable to get my servlet working.
It gets the error as below:
500 Internal Server Error
/servlet/CorpEqptEnquirySe
null
java.lang.NullPointerExcep
at CorpEqptEnquiryServlet_Act
at javax.servlet.http.HttpSer
at javax.servlet.http.HttpSer
at allaire.jrun.servlet.JRunS
at allaire.jrun.servlet.JRunS
at allaire.jrun.servlet.JRunN
at allaire.jrun.servlet.Invok
at allaire.jrun.servlet.JRunS
at allaire.jrun.servlet.JRunS
at allaire.jrun.servlet.JRunR
at allaire.jrun.servlet.JRunS
at allaire.jrun.servlet.JvmCo
at allaire.jrun.http.WebEndpo
at allaire.jrun.ThreadPool.ru
at allaire.jrun.WorkerThread.
But when I got the Javascript out and manually put in the hidden value. It works.
Cool... you are getting there :)
There are two main ways I have worked with that have worked well in achieving what you want. Both depend on you using a IIS or PWS situation. The first is one if you are using a all IE situation. Its called RDS. Go http://www.rdsdeveloper.com/ASPTutorial.html for details on it. Once setup properly you access data via ado commands and such. To access databases you have to setup a DSN on the server. By using a DSN you can pretty much query any db from there. I have done it with SQL 7 and MySQL.
If in a multibrowser situation, you can then use another method that does use a hidden java applet. It again needs IIS or PWS, but it does work in Netscape. Its called Remote Scripting. It basically sends a request to an .asp page that then executes and can send back data. It can send back delimited data or if using IE only ado objects. I have used to send back text delimited data and then split it out and use it accordingly. The cool thing about it is that since it queries a asp page you do anything in the asp page such as com objects and such to retrieve and do calculations. Here is the link on the MS site for it:
http://msdn.microsoft.com/scripting/remotescripting/rsdocs.htm
I have used it wilt Netscape 4.x. I can't remember if I have tried it with version 6 netscape. It works for sure in IE.
As I said this works if your webserver is MS.
If in a multibrowser situation, you can then use another method that does use a hidden java applet. It again needs IIS or PWS, but it does work in Netscape. Its called Remote Scripting. It basically sends a request to an .asp page that then executes and can send back data. It can send back delimited data or if using IE only ado objects. I have used to send back text delimited data and then split it out and use it accordingly. The cool thing about it is that since it queries a asp page you do anything in the asp page such as com objects and such to retrieve and do calculations. Here is the link on the MS site for it:
http://msdn.microsoft.com/scripting/remotescripting/rsdocs.htm
I have used it wilt Netscape 4.x. I can't remember if I have tried it with version 6 netscape. It works for sure in IE.
As I said this works if your webserver is MS.
hongjun