ASP可以与Web数据库以及其它程序进行交互,是一种简单、方便的编程工具。下面由我带来ASP网页程序设计中10个非常有用的实例代码。
1.如何用Asp判断你的网站的.虚拟物理路径
答:使用Mappath方法:<%= Server.MapPath("\")% >
2.我如何知道使用者所用的浏览器
答:使用the Request object方法:
3.如何计算每天的平均反复访问人数
答:解决方法
<% startdate=DateDiff("d",Now,"01/01/1990")
if strdate<0 then startdate=startdate*-1
avgvpd=Int((usercnt)/startdate) % >
显示结果
<% response.write(avgvpd) % >
that is it.this page have been viewed since November 10,1998
4.如何显示随机图象
<% dim p,ppic,dpic
ppic=12
randomize
p=Int((ppic*rnd)+1)
dpic="graphix/randompics/"&p&".gif"
% >
显示
<img src="<%=dpic% >" >
5.如何回到先前的页面
答:<a href="<%=request.serverVariables("Http_REFERER")% >" >preivous page</a >
或用图片如:<img src="arrowback.gif" alt="<%=request.serverVariables("HTTP_REFERER")% >" >
6.如何确定对方的IP地址
答:<%=Request.serverVariables("REMOTE_ADDR)% >
7.如何链结到一副图片上
答:<% @Languages=vbscript % >
<% response.expires=0
strimagename="graphix/errors/erroriamge.gif"
response.redirect(strimagename)
% >
8.强迫输入密码对话框
答:把这句话放载页面的开头
<% response.status="401 not Authorized"
response.end
% >
9.如何传递变量从一页到另一页
答:用 HIDDEN 类型来传递变量
<% for each item in request.form % >
<input namee="<%=item% >" type="HIDDEN"
value="<%=server.HTMLEncode(Request.form(item)) % >" >
<% next % >
</form >
10.怎样才能使得htm文件如同asp文件一样可以执行脚本代码
答:Internet Sevices Manager - >选择default web site - >右鼠键- >菜单属性-〉主目录- >应用程序设置(Application Setting)- >点击按钮 "配置"- >app mapping - >点击按钮"Add" - >executable browse选择 \WINNT\SYSTEM32\INETSRV\ASP.DLL EXTENSION 输入 htm method exclusions 输入PUT.DELETE 全部确定即可。但是值得注意的是这样对htm也要由asp.dll处理,效率将降低。
public class Student {private static int counter
private String no
private String name
private String sex
public Student(String no,String name,String sex) {
this.no=no
this.name=name
this.sex=sex
counter++
}
public void printStudentInfo(){
System.out.println("学生学号:"+no)
System.out.println("学生姓名:"+name)
System.out.println("学生性别:"+sex)
}
public static void printCounter(){
System.out.println("当前学生数量:"+counter)
}
}
public class Teacher {
private static Integer initNo=null
private String no
private String name
private String grade
public Teacher(String name,String grade) {
if(initNo==null){
initNo=(int)(Math.floor(Math.random()*1000)+1)
this.no=String.valueOf(initNo)
}else{
this.no=String.valueOf(++initNo)
}
this.name=name
this.grade=grade
}
public void printNo(){
System.out.println("教师工号:"+this.no)
}
}
public class Program {
public static void main(String[] args) {
Student student=new Student("001","小明","男")
student.printStudentInfo()
Student.printCounter()
student=new Student("002","小美","女")
student.printStudentInfo()
Student.printCounter()
Teacher teacher=new Teacher("张老师","六年级二班")
teacher.printNo()
teacher=new Teacher("李老师","六年级三班")
teacher.printNo()
teacher=new Teacher("王老师","六年级四班")
teacher.printNo()
}
}
运行的一种结果:
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)