javaEE6(网站第3章-jsp练习中三个例题动手做一遍;课后题2(1),(2))

时间:2024-03-15 11:46:24
  1. 两个数求和
  1. 用javascript实现。

  1. 输入、处理、输出用同一个页面(自己处理自己)。

  1. 输入1.jsp,处理和输出2.jsp。

(4)输入1.jsp,处理2.jsp,处理完转回1.jsp显示结果。

(5)输入1.jsp,处理2.jsp,输出3.jsp。

  1. Jsp

<%@ page pageEncoding="UTF-8" %>

<html>

<body>

<form method="post" action="2.jsp">

输入第一个整数:<input type="text" name="n1" value="${param.n1}"><br>

输入第二个整数:<input type="text" name="n2" value="${param.n2}"><br>

<input type="submit" value="求和"/>

</form>

</html>

  1. Jsp

<%@ page pageEncoding="UTF-8"%>

<html>

<body>

    <%

        String sn1 = request.getParameter("n1");

        String sn2 = request.getParameter("n2");

        int n1 = Integer.parseInt(sn1);

        int n2 = Integer.parseInt(sn2);

        String s="结果为:" + (n1 + n2);

        request.setAttribute("result", s);

        

    %>

    <jsp:forward page="3.jsp"></jsp:forward>

</body>

</html>

  1. Jsp

<%@ page pageEncoding="UTF-8"%>

<html>

<body>

${result}

</body>

</html>

2、登录功能实现

3.简单购物车(session应用)

2、程序设计

(1)一个项目中包含一个菜单页面menu.jsp,和几个主页面c.jsp,python.jsp,java.jsp,javaweb.jsp,每个主页面中都要显示菜单。要求活动菜单项有所区分,比如本网站的活动链接下有下划线。

Menu.jsp

<%@ page    pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html>

<head>

<style>

ul li{

display:inline;

margin:10px;

}

ul li a{

text-decoration:none;

}

</style>

</head>

<body>

<div id="ha">

       <nav style="background-color:#3a5795;height:80px">

       <div >

         <span style="color:#00ff00;font-size:18px;font-family:black">java作业</span>

       </div>

       <div >

          <ul>

             <li class="j1"><a style="color: white; font-size: 15px; font-family: black; background-color: transparent;" href="c.jsp">c++</a></li>

             <li class="j2"><a style="color: white; font-size: 15px; font-family: black; background-color: transparent;" href="python.jsp">python</a></li>

             <li class="j3"><a style="color: white; font-size: 15px; font-family: black; background-color: transparent;" href="java.jsp">java</a></li>

             <li class="j4"><a style="color: white; font-size: 15px; font-family: black; background-color: transparent;" href="javaweb.jsp">java web</a></li>

          </ul>

       </div>

       </nav>

       </div>

</body>

</html>

  1. Jsp

<%@ page    pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html>

<head>

<style>

ul li{

display:inline;

margin:10px;

}

ul li a{

text-decoration:none;

}

</style>

</head>

<body>

       <nav style="background-color:#3a5795;height:80px">

       <div >

         <span style="color:#00ff00;font-size:18px;font-family:black">java作业</span>

       </div>

      

       <div >

          <ul>

             <li class="j1"><a style="color: white; font-size: 15px; font-family: black; border-bottom: 2px solid rgb(255, 255, 255);background-color: transparent;" href="c.jsp">c++</a></li>

             <li class="j2"><a style="color: white; font-size: 15px; font-family: black; background-color: transparent;" href="python.jsp">python</a></li>

             <li class="j3"><a style="color: white; font-size: 15px; font-family: black; background-color: transparent;" href="java.jsp">java</a></li>

             <li class="j4"><a style="color: white; font-size: 15px; font-family: black; background-color: transparent;" href="javaweb.jsp">java web</a></li>

          </ul>

         

       </div>

       </nav>

c.jsp

</body>

</html>

Python.jsp

<%@ page    pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html>

<head>

<style>

ul li{

display:inline;

margin:10px;

}

ul li a{

text-decoration:none;

}

</style>

</head>

<body>

       <nav style="background-color:#3a5795;height:80px">

       <div >

         <span style="color:#00ff00;font-size:18px;font-family:black">java作业</span>

       </div>

      

       <div >

          <ul>

             <li class="j1"><a style="color: white; font-size: 15px; font-family: black;background-color: transparent;" href="c.jsp">c++</a></li>

             <li class="j2"><a style="color: white; font-size: 15px; font-family: black; border-bottom: 2px solid rgb(255, 255, 255);background-color: transparent;" href="python.jsp">python</a></li>

             <li class="j3"><a style="color: white; font-size: 15px; font-family: black; background-color: transparent;" href="java.jsp">java</a></li>

             <li class="j4"><a style="color: white; font-size: 15px; font-family: black; background-color: transparent;" href="javaweb.jsp">java web</a></li>

          </ul>

         

       </div>

       </nav>

python.jsp

</body>

</html>

Java.jsp

<%@ page    pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html>

<head>

<style>

ul li{

display:inline;

margin:10px;

}

ul li a{

text-decoration:none;

}

</style>

</head>

<body>

       <nav style="background-color:#3a5795;height:80px">

       <div >

         <span style="color:#00ff00;font-size:18px;font-family:black">java作业</span>

       </div>

      

       <div >

          <ul>

             <li class="j1"><a style="color: white; font-size: 15px; font-family: black; background-color: transparent;" href="c.jsp">c++</a></li>

             <li class="j2"><a style="color: white; font-size: 15px; font-family: black; background-color: transparent;" href="python.jsp">python</a></li>

             <li class="j3"><a style="color: white; font-size: 15px; font-family: black; border-bottom: 2px solid rgb(255, 255, 255);background-color: transparent;" href="java.jsp">java</a></li>

             <li class="j4"><a style="color: white; font-size: 15px; font-family: black; background-color: transparent;" href="javaweb.jsp">java web</a></li>

          </ul>

         

       </div>

       </nav>

java.jsp

</body>

</html>