知识回顾
1.eclipse的配置:
ASCII:1个字节(byte)8位(bit)2进制数
1G= 1G 1M 1Kbyte
500 byte int long double
01111111 =2^8-1=255
1个汉字,是两个字节 GBK UTF-8
配置服务器
2.JSP基本语法
注释:
<%-- --%> // /* */
表达式:<% Java代码 %>
页面提交数据 表单
接收数据
request.getParameter(“参数”)返回值是String类型
1.声明:
变量 方法 类 <%! %>
<script type="text/javascript">
var n=document.getElementById("number").value;
if(n==null||n==""){
return false;
}else{
return true;
}
</script>
</head>
<body>
<%!
int jiecheng(int n){
int r=1;
for(int i=1;i<n;i++){
r*=i;
}
return r;
}
%>
<form onsubmint="return check()" action="">
<!-- <form sethod="" action="jiecheng.jsp"> -->
请输入一个数:<input type="text" name="num">
<input type="submit" value="提交">
</form>
<%
int r=1,n=0;
if(request.getParameter("num")!=null){
n=Integer.parseInt(request.getParameter("num"));
}else{
out.print("数据不能为空");
}
/* for(int i=1;i<n;i++){
r*=i;
} */
r=jiecheng(n);
%>
<%=n %>的阶乘是:<%=r%>
</body>
.JS与JSP区别
JS:
JS的动态是指让网页的某些东西动起来或者在客户端和客户进行交互,比如在客户端进行密码验证等;
JSP:
JSP的动态并不能实现JS那种动起来的效果,它的动态只是指它可以对客户端发来的消息进行处理,并反馈回客户端,
4.JSP中声明变量的区别:
全局变量与局部变量
(1).
① 定义局部变量、语句: <% %>
② 定义全局变量、方法和类: <%! %>
(2).
访问一次调用一次servlet方法
每次都赋初值为0
<body>
<%!int x=0;
%>
<%
x++;
int y=0;
y++;
%>
全局变量x的值:<%=x %>
局部变量y的值:<%=y %>
</body>
运行一次:
全局变量x的值:1 局部变量y的值:01
运行两次:
全局变量x的值:2 局部变量y的值:1
.
.
.
运行16次:
全局变量x的值:16局部变量y的值:1