JSP页面,脚本标签

论坛 期权论坛 脚本     
已经匿名di用户   2022-5-29 19:34   938   0


/




<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>使用文件包含include指令</title>
</head>
<body style="margin:0px;">
<%@ include file="top.jsp"%>
<table width="781" height="279" border="0" cellpadding="0" cellspacing="0" background="images/center.JPG">
<tr>
<td>&nbsp;</td>
</tr>
</table>
<%@ include file="copyright.jsp"%>
</body>
</html>









//



通过代码片段和JSP表达式在JSP页面中输出九九乘法表





<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
<%
String str = ""; //声明保存九九乘法表的字符串变量
//连接生成九九乘法表的字符串
for (int i = 1; i <= 9; i++) {// 外循环
for (int j = 1; j <= i; j++) { // 内循环
str += j + "*" + i + "=" + j * i;
str += "&nbsp;"; //加入空格符
}
str += "<br>"; // 加入换行符
}
%>
<table width="440" height="85" border="1" cellpadding="0" cellspacing="0" style="font:9pt;"
bordercolordark="#666666" bordercolorlight="#FFFFFF" bordercolor="#FFFFFF">
<tr>
<td height="30" align="center">九九乘法表</td>
</tr>
<tr>
<td style="padding:3pt">
<%=str%> <!-- 输出九九乘法表 -->
</td>
</tr>
</table>
</body>


</html>













///

在JSP页面添加隐藏页面




<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>隐藏注释的应用</title>
</head>
<body>
<%-- 显示用户信息开始 --%>
用户名:无语<br>
部&nbsp;&nbsp;门:Java Web部门 <br>
权&nbsp;&nbsp;限:系统管理员
<%-- 显示用户信息结束 --%>
</body>
</html>












///


应用<jsp:include>表示包含网站Banner和版栏信息栏




<%@ page pageEncoding="GB18030"%>
<%
String copyright="&nbsp;All Copyright &copy; 2009 吉林省明日科技有限公司";
%>
<table width="778" height="61" border="0" cellpadding="0" cellspacing="0" background="images/copyright.JPG">
<tr>
<td> <%= copyright %></td>
</tr>
</table>












<%@ page language="java" contentType="text/html; charset=GB18030" pageEncoding="GB18030"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>使用&lt;jsp:include&gt;动作标识包含文件</title>
</head>
<body style="margin:0px;">
<jsp:include page="top.jsp"/>
<table width="781" height="279" border="0" cellpadding="0" cellspacing="0" background="images/center.JPG">
<tr>
<td>&nbsp;</td>
</tr>
</table>
<jsp:include page="copyright.jsp"/>
</body>
</html>


















<%@ page pageEncoding="GB18030"%>
<img src="images/banner.JPG">













///


应用<jsp:forward>标识将页面转发到用户登入界面





<%@ page language="java" contentType="text/html; charset=GB18030" pageEncoding="GB18030"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>中转页</title>
</head>
<body>
<jsp:forward page="login.jsp"/>
</body>
</html>









<%@ page language="java" contentType="text/html; charset=GB18030" pageEncoding="GB18030"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>用户登录</title>
</head>
<body>
<form name="form1" method="post" action="">
用户名: <input name="name" type="text" id="name" style="width: 120px"><br>
密&nbsp;&nbsp;码: <input name="pwd" type="password" id="pwd" style="width: 120px"> <br>
<br>
<input type="submit" name="Submit" value="提交">
</form>
</body>
</html>













//



在JSP页面中输出完整的时间,格式为“年 月 日 时:分:秒"




<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">


<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>


<body>
在JSP页面中输出完整的时间,格式为:“年 月 日 时:分:秒”
<br>
<%
Date date = new Date();
String year = String.format("%tY", date); //将date进行格式化
String month = String.format("%tm", date);
String day = String.format("%td", date);
String hour = String.format("%tH", date); //将date进行格式化
String minute = String.format("%tM", date);
String second = String.format("%tS", date);
String dateStr = year + "年" + month + "月" + day + "日 " + hour + "时"
+ minute + "分" + second + "秒";
%>
现在时间是:<%=dateStr %>
</body>
</html>














/





计算5的阶乘并在JSP页面中输出



<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">


<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>


<body>
计算5的阶乘并在JSP页面中输出。
<br>
<%
String str = "";
int n = 5;
long result = 1;
if ((n < 0) || (n > 17)) {
str = "n的取值范围是0至17,大于17会超出long类型范围";
} else if (n == 0) {
str = "0的阶乘等于1";
} else {
for (int i = n; i > 0; i--) {
result *= i;
}
str = n + "的阶乘等于:" + result;
}
%>
<%=str %>
</body>
</html>








/


在JSP页面中输出字符"*"组成的金字塔


<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">


<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>


<body>
在JSP页面中输出字符“*”组成的金字塔。
<br>
<%
String str = "";
for (int i = 0; i < 15; i++) {
for (int j = 15; j > i; j--) {
str += "&nbsp;";
}
for (int j = 0; j < i; j++) {
str += "*&nbsp;";
}
str += "<br>";
}
%>
<%=str%>
</body>
</html>










分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:81
帖子:4969
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP