A little ASP problem, error and personal experience

zhaozj2021-02-16  146

Published on 2003-9-9 12:20:00

Reposted from: http://www.5d.cn/bbs/newsdetail.asp? Id = 9178311. 省 省 DIM, convenient but also hidden dangers! After the application variable is standard method: DIM AA = "1" In fact, you don't write DIM or: a = "1" system does not think an error, it will automatically determine that A is an existing variable, existence Just continue, automatically apply for you if you don't exist! It seems that the system is so smart and smart, but hidden dangers! Do you know what I mean? The system is likely to be smart, good to help! Question 1: If I have applied for a variable in front, such as Administrator, I want to assign this variable, I am unfortunate to write a letter or write a letter, such as administratar = "ME " Yes, the program may be able to run, but it is logically already chaotic, because the system does not report an error (or reporting a different mistake to mislead you), you can't quickly locate it, if the program is large, you spend How do you think after a lot of time? You must really want the system "self-employment". If the system is reported to a Administratar variable name does not exist, I can quickly know that I spell, and correct the problem, not to "indulge" in the system "self Do your love "! Another hidden danger brought by DIM will speak! 2. The variables declared within the function will not interfere with the external variables! For example: <% @ language = "vbscript" codepage = "936"%> <% DIM AA = "1" function getStr () Dim aa = "2" End FunctionResponse.write a & "
" getStr () Response .Write a & "
"%> "The display function is not interfere with the outside, its scope is the inside of the function, in fact, you should know other languages! But you must first declare that if Dim a in the function is removed, then the A is thinking is an external A, and the result will change! The file is applied in the file, his scope is this file. 3. Let people love and hate include! Include allows the ASP program to be more structured, and some common functions can be shared by other files! He has brought the benefits while you have to pay attention to the shortcomings! Now returning to the first point to say that DIM, what I said earlier is the system "good", it has become a declaration variable.

Now, the exact opposite, I want to declare the variable, but the system is assigned, because DIM can also declare variables, for the province, the province, the province, it is often unable to stop this temptation (I sometimes like this to apply , 嘿), but can you guarantee that you are not in front of the program you apply? If there is this variable name in front, don't you apply for a value? In the same file, you will rarely make this mistake, but don't forget to include it, if you have any variables you apply in the file included, then you will run, logically, logical has become a problem. . If you don't lazy, apply for DIM, when you report an error, you are lucky to know this variable name already exists! Can be corrected soon! Now discuss more complicated situations, if you include two files, there are the same variable name in these two files. If both use DIM applications, it is ok, it is just an error, saying that the variable name already exists. It will be aware of the problem soon. Now you can understand why I say the second point of role. Due to the role domain, different files are generally "fight" with the same name variables. However, if you are in addition to another file, the problem is troublesome, so if you write the ASP file is ready to be included, please prevent the same name from happening. Going back to the original discussion, if the two include files apply DIM, it is ok, but the containment file is applied by omitting the DIM application, the problem is coming, the following omitted DIM application is assigned, and it is, It is in two include files, it is very hidden, and it is more difficult to find problems! In summary, everyone can write some simple example to experience the problems, and finally recommend: 1. Please apply for re-use with DIM first! Especially multi-person complex procedures! 2. Assign the value to the variable, please pay attention to the variable spell! 3. Carefully understand the file of the include. *** Now, check the error: In fact, looking for problems more important than code writing! I personally experience, the problem is divided into three categories: 1. Report an error, compilation system encountered in the compilation system, it will give an error message, this is the most favorite problem of programmer, huh, not metamorphosis, but this The problem is the simplest! 2. Logical classes, more annoying issues, program compilation success, can also run, but the result of display is not the result of your logic. Oh, my god! What to do, there is no prompt information, you can only analyze the result of the wrong results with experience and feel, then check the source code, smooth, a few minutes, and there is no result! 3. Performance, very terrible issues, program compilation success, can also run normally, it is normal! However, occasionally separation time to give you a mistake, you don't know what the mistake is triggered, or the program performance is not as high as the same program, the operation is slow, these problems, some a month can solve, there is It is almost disadvantaged, not good.

I have been tossed by this problem! So, if you want to learn to program, try to solve the problem, especially like the ASP program, logical problems, the problem is basically an error, an error message, an error position, the analysis and analysis of its own analysis should not It is difficult to resolve. I think some people are willing to spend three days in the forum to tell themselves, why don't you solve it? I find a problem, I have a proficiency, this is the wealth of the programmer! *** Little programmer's experience: Don't think that you can write a few lines of code, I think it is a programmer, waiting for you to go to the software company for a few years, you will understand what is the programmer, write code Not counting, the code is wrong, optimized code, write software text (not a simple user manual, but project application, project preliminary design manual, project detailed design book, database design manual, project test manual, user manual , User maintenance manual, etc.), in fact you will design, does not mean you can develop. In fact, I don't do well in some respects, such as writing software documents, huh, I think about it is very horrible, writing software documents is more painful than writing programs! I did a three-year Delphi programmer, although I made a good software project when I left the company. But I still feel that I haven't stopped, so I still keep supplementing other technologies. This social competition is already very intense. The more you don't work hard, you strive to be unemployed! For the first question, I strongly recommend that you use DIM before using the variable, and write a line of code is not very difficult. Then use <% Option Explicit%> in the ASP file header, so if you accidentally write the variable name, return the variable does not have a defined error, you can easily find the error location, otherwise the variable is one NULL value. In addition, the second problem is said to be combined with Option Explicit. Sometimes we need to include multiple files (such as HEAD definition, top navigation, etc.), while Option Explicit in an ASP Application (Note that this is Application, specifically, instead of Page, does not represent a page) can only be used once. Therefore, Option Explicit is best not to put inside the include file to avoid confusion by multiple pages. Again a small problem about INCLUDE. Generally, if the file you need to include is in the current directory, we can use it directly to include it directly. However, many times we have n need to include files. So, in order to facilitate management, we will put them in an Inc or Include directory. This way, sometimes it is written:

This is what I want to discuss. Please pay attention to use .. You can access the upper part of the directory, due to a security hidden danger: Users have possible illegal reference site external files. Based on this reason, the IIS LockDown tool released by Microsoft shields this reference method, and Microsoft is shielded by default on the IIS6.0 of Windows Server 2003. For this containing files within this directory, it is recommended to use this security reference method: Welcome more beneficial exploration and discussion

转载请注明原文地址:https://www.9cbs.com/read-8631.html

New Post(0)