1.JSP中的Page指令
通过设置内部的多个属性定义整个页面的属性
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>language:指定JSP页面使用的脚本语言
import:通过该类属性引用脚本语言中使用到的类文件
contentType:用来指定JSP页面所采用的编码方式
2.JSP中的小脚本与表达式
在JSP页面中计算两个数的和,将结果输出显示
<%@ page language="java" import="java.util.*,java.text.*" contentType="text/html; charset=utf-8" %>
<html>
<head><title>计算求和</title></head>
<body>
两个数的求和结果为:
<%
int numA = 4, numB = 5 ;
int result = numA+numB;
%>
<%=result %>
</body>
</html>
<% 小脚本%> <%表达式>
3.JSP输出1-100间的质数(素数)
代码:
<%
int i,j,x,sum;
for (i = 2; i <= 100; i++) {
for (j = 2; j < i; j++) {
if (i % j == 0){
x=j;
break;}
}
if (j >= i) {
%>
<%=i%>
<%
}
}
%> 结果:2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 4.JSP打印出3*5的表格
5.JSP的时间
<body>
<!-- 1-->
<% Date date = new Date(); %>
当前时间:<%=date %><br />
<!-- 2-->
<% Date date1 = new Date();
//简单日期格式
SimpleDateFormat a = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String time =a.format(date1);
%>
当前时间:<%=time %><br />
<!-- 3.使用方法,只可以在本页面中使用 -->
<%! String getDate(){
Date date2 = new Date();
SimpleDateFormat a1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String time1 =a1.format(date2);
return time1;
}
%>
当前时间:<%=getDate() %>
<br />
<!-- 4.调用类,可以再整个项目中调用 -->
<%
FomatDate fd =new FomatDate();
String times =fd.getDate();
%>
当前时间:<%=times %>
</body>当前时间:Mon Aug 28 10:14:09 CST 2017
当前时间:2017-08-28 10:14:09
当前时间:2017-08-28 10:14:09
当前时间:2017-08-28 10:14:09
223

被折叠的 条评论
为什么被折叠?



