大学jsp实验3include指令的使用

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

1、include指令的使用

(1)编写一个名为includeCopyRight.jsp的页面,页面的浏览效果如下:

要求“2016”这个值可以实现动态更新。请写出页面代码:

 1 <%@ page contentType="text/html;charset=UTF-8" language="java" %>
 2 <%@ page import="java.util.*" %>
 3 <html>
 4 <head>
 5     <title>includeCopyRight</title>
 6 </head>
 7 <body>
 8 <%
 9     Calendar cal = Calendar.getInstance();
10     String year =String.valueOf(cal.get(Calendar.YEAR));
11 %>
12 <center>
13     <p>..............................................................................................................................................</p>
14     <p>颜志军(http://www.yanzhijun.net) 版权所有 2010-<%=year %></p>
15 </body>
16 </html>

(2)编写名为shiyan3_2_1.jsp和shiyan3_2_2.jsp两个JSP页面,页面内容自定,但要求使用include指令将includeCopyRight.jsp页面中显示的版权信息包含进shiyan3_2_1.jsp和shiyan3_2_2.jsp页面中。请写出相应代码:

shiyan1:

 1 <%@ page contentType="text/html;charset=UTF-8" language="java" %>
 2 <html>
 3 <body>
 4 <%!
 5     double multi(double x, double y) {
 6         return x * y;
 7     }
 8 %>
 9 <%
10     double x = 3.56;
11     double y = 18;
12     out.print("调用方法计算" + x + "" + y + "之积:");
13     out.print(multi(x, y) + "<br/>");
14 %>
15 <%@include file="includeCopyRight.jsp" %>
16 </body>
17 </html>

shiyan2:

 1 <%@ page contentType="text/html;charset=UTF-8" language="java" %>
 2 <html>
 3 <body>
 4 <%!
 5     int count = 0;
 6     synchronized void setCount(){
 7         count++;
 8     }
 9 %>
10 <%
11     setCount();
12     out.println("您是第"+count+"个访问本站的用户");
13 %>
14 <%@ include file="includeCopyRight.jsp" %>
15 </body>
16 </html>

(3)编写名为shiyan3_2_3.jsp的页面,其中显现“请输入两个整数,单击提交按钮求这两个整数的平方差”。再编写一个名为shiyan3_2_4.jsp页面,其中显示表单,输入两个整数后,单击提交按钮后可以显示出两数的平方差,效果如下图所示。要求在shiyan3_2_3.jsp包含shiyan3_2_4.jsp。

shiyan3_2_3.jsp:

 1 <%@ page contentType="text/html;charset=UTF-8" language="java" %>
 2 <html>
 3 <head>
 4     <title>平方差</title>
 5 </head>
 6 <body>
 7 <P>输入两个整数,单击提交按钮求这两个整数的平方差</P>
 8 <%@ include file="shiyan3_2_4.jsp" %>
 9 <%
10     String str1 = request.getParameter("one");
11     String str2 = request.getParameter("two");
12     try {
13         int num1 = Integer.parseInt(str1);
14 
15         int num2 = Integer.parseInt(str2);
16         int num = num1*num1-num2*num2;
17         out.println("你输入的两个整数的平方差是:"+num);
18     }catch (NumberFormatException e){
19     }
20 %>
21 </body>
22 </html>

shiyan3_2_4.jsp:

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>计规范化算</title>
</head>
<body>

<form action="" method="post" name="form">
    整数1:<input type="text" name="one"><br><br>
    整数2:<input type="text" name="two"><br><br>
    <input type="submit" value="提交" name="submit">
</form>

</body>
</html>

转载于:https://www.cnblogs.com/lgqrlchinese/p/8987939.html

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

本版积分规则

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

下载期权论坛手机APP