Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

retrieving data from mysql

Status
Not open for further replies.

sensory21

Programmer
Jan 27, 2004
79
GB
Hi all,

I have an index.jsp page with a function calling a javascript page:
<script language="JavaScript">
BuildPanel();
</script>

In the javascript page I have:
var users = new Array();
users[0] = new Array("guest","staff","staff.jsp");
users[1] = new Array "guest1","customer","customer.jsp");

What I would like to do is to replace the usernames and passwords from the js file and retrieve them from mysql database, anyone could tell me how to do that?

Regards,
Vero
 
You would have to retrieve them from the mySQL database using server-side Java (since you are running JSPs and this is the default language for JSP).

Once you have them in an object server-side, you need to get them to the client. You may find the best solution is to write them out to a javascript variable as you initially build the page.

Code:
<script type="text/javascript">
var dataFromDatabase = "<%= myDataVariable %>";
</script>

You could then run some javascript code (when the page has loaded) to manage this data.

Cheers,
Jeff
 
Cheers Jeff but I don't get it! can you advise me a link where i could find some help?

Thanks
Vero
 
You cannot connect to a mySQL database using javascript on the browser. You can only do this on the server (before the page is actually delivered to the client computer).

You will have to write some code on the JSP page that connects to the mySQL database, performs the query, captures the result and massages it into a format ready for delivery to the page.

If this is something that you are not comfortable with -- please be aware that this is a Javascript forum (not a Java, nor JSP forum)... and you may find it more useful to look there for a solution.

To answer your request, I would suggest typing the following into google for your search query:

JSP mySQL tutorial example

Some links include:


All the best,
Jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top