<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%!public int continueSum(int start, int end) {
int sum = 0;
for (int i = start; i <= end; i++)
sum = sum + i;
return sum;
}%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'index.jsp' starting page</title>
</head>
<body>
<script type="text/javascript">
var userTime = new Date();
var hour = userTime.getHours();
var minute = userTime.getMinutes();
document.write("浏览器时间:"+hour + ":" + minute);
</script>
<%
Date d = new Date();
int hour = d.getHours();
int minute = d.getMinutes();
out.print("服务器时间:"+hour + ":" + minute);
if (hour >= 0 && hour <= 12) {
out.print("上午好");
} else if (hour >= 13 && hour <= 17) {
out.print("下午好");
} else {
out.print("晚上好");
}
%>
</body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'index.jsp' starting page</title>
</head>
<body>
<%! public void run(int year){
if((year%4==0&&year%100!=0)||(year%400==0)){
System.out.print(year+"是闰年");
}
else{
System.out.print(year+"不是闰年");
}
} %>
<% int year=2023;
run(year);
%>
</body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'index.jsp' starting page</title>
</head>
<body>
<%for(int i=1;i<=5;i++){ %>
<hr width="<%=i*100%>">
<%
} %>
</body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <%!public int continueSum(int start, int end) { int sum = 0; for (int i = start; i <= end; i++) sum = sum + i; return sum; }%> <! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> < html > < head > < title >My JSP 'index.jsp' starting page</ title > </ head > < body > < script type="text/javascript"> var userTime = new Date(); var hour = userTime.getHours(); var minute = userTime.getMinutes(); document.write("浏览器时间:"+hour + ":" + minute); </ script > <% /* Date d = new Date(); int hour = d.getHours(); int minute = d.getMinutes(); out.print("服务器时间:"+hour + ":" + minute); if (hour >= 0 && hour <= 12) { out.print("上午好"); } else if (hour >= 13 && hour <= 17) { out.print("下午好"); } else { out.print("晚上好"); } */ %> </ body > </ html > |
第二题注释
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>My JSP 'index.jsp' starting page</title> </head> <!-- 这个是HTML注释 --> <body> <%! public void run(int year){ if((year%4==0&&year%100!=0)||(year%400==0)){ System.out.print(year+"是闰年"); } else{ System.out.print(year+"不是闰年"); } } %> <% int year=2023; run(year); %> </body> </html>