Introduction to ASP Programming Using JSP programming ideas

Source: Internet
Author: User
Tags dsn microsoft iis

JSP (Java Server Page) and ASP (Active Server Page) are both common dynamic web pages and can be embedded into HTML programs. JSP programming ideas are similar to ASP. However, there are essential differences between the two, mainly from the following aspects:

1) Web Server support: most common Web servers, such as Apache, Netscape, and Microsoft IIS, support JSP pages. Only Microsoft IIS and Personal Web Server support ASP.

2) platform support: JSP is platform independent. As long as it is a platform that can run general Java programs, JSP programs are supported. The Windows platform can support ASP well. However, the dependency of ASP on Win32-based models makes it difficult for other platforms.

3) Component Model: JSP is built on reusable and cross-platform components, such as JavaBeans, Enterprises JavaBeans, and custom tag libraries, ASP uses the Win32-based COM component model.

4) scripting language: JSP can use Java programming language or JavaScript as the scripting language, while ASP uses VBScript or Jscript as the scripting language.

5) Security: JSP uses the Java security model, while ASP uses the security structure of Windows NT.

6) connection to the Access Database: JSP uses JDBC to establish a connection with the Access database, while ASP uses Data Active Objects for the Access database.

7) custom tags: JSP can be expanded using the custom tag library. ASP cannot be expanded without the custom tag library in ASP.

The following program has a general FRAME function. In fact, you can add some functions by yourself. For example, to start Datcbase connection, you can set the variable and then use INIT () to select Datcbase of different types.

 
 
  1. <%
  2. 'On Error Resume Next
  3. Class ConnEx
  4. PubliC ConnEx
  5. PubliC DBpath '--------- Datcbase path
  6. PubliC DBtype '--------- DatcbaseTYPE 1 (ACCess) 2 (SqlServer) 3 (expandable)
  7. PubliC ConnMethod '-------- connection method DSN, non-DSN)
  8. PubliC User
  9. PubliC Pass
  10. Sub Class_initialize
  11. End Sub
  12.  
  13. Sub Init ()
  14. ConnStr="Driver = {MiCrosoft ACCess Driver (*. mdb)}; dbq ="& Server. MapPath ("Date. mdb ")
  15. SetConnEx=Server. CreateobjeCt ("ADODB. CONNECTION ")
  16. ConnEx. Open ConnStr
  17. CatChError ("Class_Terminate ")
  18. End Sub
  19.  
  20. Sub CatChError (Str)
  21. If Err Then
  22. Err. Clear
  23. Class_Terminate ()
  24. Response. Write ("caught error, program ended! At "& Str ")
  25. Response. End ()
  26. End If
  27. End Sub
  28.  
  29. '*************************************** ***
  30. '* You can use SQL statements to check whether a record exists, which is prone to errors.
  31. '*************************************** ***
  32.  
  33. FunCtion HasReCordBySql (SQL)
  34. Call CheCkSql (SQL, "R ")
  35. Dim Rs, HasR
  36. SetRs=ConnEx. ExeCute (SQL)
  37. CatChError ("HasReordSql ")
  38. If Not (Rs. eof Or Rs. bof) Then
  39. HasR=False
  40. Else
  41. HasR=True
  42. End If
  43. Rs. Close
  44. SetRs=Nothing
  45. HasRHasReCordBySql= HasR
  46. End FunCtion
  47.  
  48. '***************************************
  49. '* Use ID to check whether a record exists
  50. '***************************************
  51.  
  52. FunCtion HasReCordById (StrTableName, IntID)
  53. 'Checkvalue (IntID, 1)
  54. Dim Rs, HasR
  55. SQL="SeleCt top 1 * from"& StrTableName & "WhereId= "& IntID
  56. Call CheCkSql (SQL, "R ")
  57. SetRs=ConnEx. ExeCute (SQL)
  58. CatChError ("HasReCordByID ")
  59. If Not (Rs. eof Or Rs. bof) Then
  60. HasR=False
  61. Else
  62. HasR=True
  63. End If
  64. Rs. Close
  65. SetRs=Nothing
  66. HasRHasReCordById= HasR
  67. End FunCtion
  68.  
  69. '*************************************** *******
  70. '* Obtain the record set using SQL language Rule Statements
  71. '*************************************** *******
  72. FunCtion GetRsBySql (SQL)
  73. Call CheCkSql (SQL, "R ")
  74. Dim Rs
  75. SetRs=Server. CreateObjeCt ("Adodb. ReCordSet ")
  76. Rs. Open SQL, ConnEx, 1, 1
  77. SetGetRsBySql= Rs
  78. End FunCtion
  79.  
  80. '*************************************** ******
  81. '* Get the value of a field
  82. '*************************************** ******
  83. FunCtion GetValueBySql (SQL)
  84. Call CheCkSql (SQL, "R ")
  85. Dim Rs, ReturnValue
  86. SetRs=ConnEx. ExeCute (SQL)
  87. CatChError ("GetValueBySql ")
  88. If Not (Rs. Eof Or Rs. Bof) Then
  89. ReturnValue=Rs(0)
  90. Else
  91. ReturnValue="No records"
  92. End If
  93. Rs. Close
  94. SetRs=Nothing
  95. GetValueBySql=ReturnValue
  96. End FunCtion
  97.  
  98. '============================== Update,Insert================================
  99.  
  100. '*************************************** ******
  101. '* Use SQL language rules to modify Data
  102. '*************************************** ******
  103. FunCtion UpdateBySql (SQL)
  104. Call CheCkSql (SQL, "w ")
  105. ConnEx. ExeCute (SQL)
  106. CatChError ("UpdateBySql ")
  107. UpdateBySql=True
  108. End FunCtion
  109.  
  110. '*************************************** *****
  111. '* Insert Data using SQL language Rule Statements
  112. '*************************************** *****
  113. FunCtion InsertBySql (SQL)
  114. Call CheCkSql (SQL, "w ")
  115. ConnEx. ExeCute (SQL)
  116. CatChError ("InsertBySql ")
  117. InsertBySql=True
  118. End FunCtion
  119.  
  120. '================================Delete==================================
  121.  
  122. '*************************************** *****
  123. '* Use SQL statements to delete rules
  124. '*************************************** *****
  125. FunCtion DeleteBySql (SQL)
  126. Call CheCkSql (SQL, "D ")
  127. ConnEx. ExeCute (SQL)
  128. CatChError ("DeleteBySql ")
  129. DeleteBySql=True
  130. End FunCtion
  131.  
  132. '*************************************** *****
  133. '* Check the SQL language Rule statement permissions, and check the statements based on the Flag.
  134. '*************************************** *****
  135. Sub CheCkSql (SQL, Flag)
  136. Dim StrSql, SinCounts, DouCounts, I
  137. StrSql=LCase(SQL)
  138. SinCounts=0
  139. DouCounts=0
  140. ForI=1To Len (StrSql)
  141. If Mid (StrSql, I, 1) = "'" ThenSinCountsSinCounts= SinCounts + 1
  142. If Mid (StrSql, I, 1) = "ThenDouconfulfill=DouCounts+ 1
  143. Next
  144.  
  145. If (SinCounts Mod 2)<>0 Or (DouCounts Mod 2)<>0 Or Instr (StrSql ,";")>0 Then
  146. Call Class_Terminate ()
  147. Response. Write ("SQL language Rule error! ")
  148. Response. End ()
  149. End If
  150. SeleCt Case Flag
  151. Case "R", "r ":
  152. If Instr (StrSql, "delete ")>0 Or Instr (StrSql, "update") Or Instr (StrSql, "drop ")>0 Or Instr (StrSql, "insert ")>0 Then
  153. Class_Terminate ()
  154. Response. Write ("You are not authorized to run the Write operation ")
  155. Response. End ()
  156. End If
  157. Case "W", "w ":
  158. If Instr (StrSql, "delete ")>0 Or Instr (StrSql, "drop ")>0 Or Instr (StrSql, "seleCt ")>0 Then
  159. Class_Terminate ()
  160. Response. Write ("You are not authorized to run the delete operation ")
  161. Response. End ()
  162. End If
  163. Case "D", "d ":
  164. Case Else:
  165. Response. Write ("The CheCkSql flag is incorrect! ")
  166. End SeleCt
  167. End Sub
  168.  
  169. Sub Class_Terminate
  170. If Not IsEmpty (FriendConn) Then
  171. FriendConn. Close
  172. SetFriendConn=Nothing
  173. CatChError ()
  174. End If
  175. End Sub
  176. End Class
  177. %> 

We will introduce ASP Programming Using JSP programming.

  1. Methods for constructing JSP and Javabean development and release Environments
  2. Analysis of JSP Design Mode
  3. What is JSP and its strong weakness?
  4. How Tomcat improves performance on JSP pages
  5. Use of scripts Based on JSP tutorials

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.