130 likes | 308 Vues
ASP – JavaScript using MS Access. I450/451 – 2004 Indiana University School of Informatics. ASP. Active Server Pages, or ASP, is run on an Web hosting server such as IIS. It is a scripting language used to provide dynamic content to requesting clients on the Internet.
E N D
ASP – JavaScriptusingMS Access I450/451 – 2004 Indiana University School of Informatics
ASP Active Server Pages, or ASP, is run on an Web hosting server such as IIS. It is a scripting language used to provide dynamic content to requesting clients on the Internet. ASP provides a common library of commands to be used by a programming language that supports ASP. This means that you can use many different languages while programming In ASP, each calling the same ASP methods and objects (generally). • JavaScript • Visual Basic • C# • … Languages
ASP ASP can be written in a single page, but it is best to organize your ASP into files. This creates a site architecture, and makes programming easier, and Keeps your site more consistent. Library.asp Global variables Global functions TemplateTop.asp CSS HTML Header Index.asp help.asp search.asp TemplateBottom.asp HTML Footer
ASP The language you use in ASP is declared in the top line of an ASP file. Here is an example of a declaration for VB and JavaScript: JavaScript <%@ Language=“JavaScript” %> VB script <%@ Language=“VBScript” %> Note: If you include a file in ASP, then you cannot put this line on top of each file, meaning in the include file and the file that is including it. Just put it in the include file only.
ASP - Variables Declaring – JavaScript: var variableName; Declaring – VBScript: Dim variableName;
ASP – Block Delimiter ASP allows mixing of regular HTML and ASP in one file. To differentiate between ASP and HTML you use a block delimiter which is signified by: <% or %> Example: html html <% ASP ASP %> html html
ASP – Sample File <%@ Language=JavaScript%> <% var name = “Benji”; var cash = “$1”; var dates = 0; %> <html> <body> <% Response.write(name); %> has had <% Response.write(dates); %> because he has <% Response.write(cash); %> dollars. </body> <html>
Creating the file. • Using dreamweaver, notepad, or your editor of choice, create an asp file. • You don’t have to write about my dollar dates…. Or lack of. Create a message of your own.
ASP – Running it Ok, lets try it out. Using SSH, log into Boole Host name: boole.informatics.indiana.edu User name: yourIUUserName Password: yourIUPassword Upload your ASP file, and then we will access it from the web. We will figure out the details to this in class…. I hope.
ASP – Accessing from the web To view your ASP page open a browser and type in the following address… replacing userName with your IU username. In the future, we hope to use: http://www.boole.informatics.indiana.edu/i450/ Open SSH www.boole.informatics.indiana.edu For today: www.informatics.indiana.edu/dgroth/courses/i450/tech/asp/test2/yourASPpage.asp
ASP – Receiving Form Variables What this code does. When you submit a form, the form variables reach a page like this one. This page in particular expects one of your form input fields to be called “varName”. The if statement is a catch all, no matter what is in the form variable, or if it doesn’t even exist, your ASP page will not crash when protected by this if statement. var varValue = “”; if ((Request.QueryString(“varName”).Count != 0) && (Request.QueryString(“varName”) != "")) { varValue = Request.QueryString(“varName”).Item; } // end if (form variable is defined and not empty)
ASP & MS Access • Although Access isn’t built for holding huge amounts of data, it is useful in many situations. What is nice about it is that Access is generally easy to use.
ASP & Access <%@ Language=JavaScript%> <% var sql = “select * from user; var dataSource = “Data Source=i450test; UID=i450test; PWD=i450test;”; var db_connection = Server.CreateObject("ADODB.Recordset"); db_connection.Open (sql, dataSource, 3, 3); rs = db_connection; %> <html> <body> <table> <tr><th>Name:</th><th>Occupation</th> if (rs.EOF) Response.Write("No entries"); else { rs.MoveFirst(); while (!rs.EOF) { %> <tr> <td> <% Response.Write(rs.Fields(“name")) %></td> <td> <% Response.Write(rs.Fields(“occupation”)) %></td> </tr> <% } // end while } // end if %> </table> </body> </html>