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

  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>

Javaweb.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 ; background-color: transparent ;" href="java.jsp" >java</a></li>

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

</ul>

</div>

</nav>

javaweb.jsp

</body>

</html>

  1. 设计一个用户注册表单,用户填写完并提交后输出用户填写的信息。如图所示:
  1. Jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"

pageEncoding="UTF-8" %>

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8" >

<body>

<a href="2.jsp?p1=abc&p2=123" ></a>

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

用户名:<input type="text" name="xm" >(必填)

<br>

密码:<input type="password" name="password" >(必填)

<br>

确认密码:<input type="password" name="turepassword" >

<br>

性别:

<input type="radio" name="xingbie" value=" 男" >男

<input type="radio" name="xingbie" value=" 女" >女

<br>

爱好:

<input type="checkbox" name="aihao" value=" 计算机" >计算机

<input type="checkbox" name="aihao" value=" 音乐" >音乐

<input type="checkbox" name="aihao" value=" 体育" >体育

<input type="checkbox" name="aihao" value=" 文学" >文学

<br>

<div>

<label for="xingzuo" >星座</label>

++<++ ++select++ ++name++ ++=++ ++"xingzuo"++ ++id++ ++=++ ++"xingzuo"++ ++>++

<option >巨蟹</option>

<option >水瓶</option>

<option >白羊</option>

<option >其他</option>

++<++ ++select++ ++>++

</div>

<br>

<div>

<label for="message" >个人简介</label>

<textarea name="message" id="message" cols="50" rows="4" ></textarea>

</div>

<input type="submit" value=" 提交" />

<input type="reset" value=" 重置" />

</form>

</body>

</html>

  1. Jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"

pageEncoding="UTF-8" %>

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8" >

</head>

<body>

<%

out.print(request.getParameter("p1")+","+request.getParameter("p2")+","+request.getParameter("p3")+","+request.getParameter("p4")+","+request.getParameter("p5")+","+request.getParameter("p6"));

%>

</body>

</html>

  1. Jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"

pageEncoding="UTF-8" %>

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8" >

</head>

<body>

<%

request.setCharacterEncoding("UTF-8");

out.print("您的姓名是:"+request.getParameter("xm")+"<br/>");

out.print("您的密码是:"+request.getParameter("password")+"<br/>");

out.print("您的性别是:");

String[] xingbie=request.getParameterValues("xingbie");

if (xingbie!=null ){

for (String a:xingbie){

out.print(a+" ");

}

}

out.print("<br/>");

out.print("您的爱好是:");

String[] aihao=request.getParameterValues("aihao");

if (aihao!=null ){

for (String s:aihao){

out.print(s+" ");

}

}

out.print("<br/>");

out.print("您的星座是:");

String[] xingzuo=request.getParameterValues("xingzuo");

if (xingzuo!=null ){

for (String b:xingzuo){

out.print(b+" ");

}

}

out.print("<br/>");

out.print("您的个人简介是:"+"<br/>"+request.getParameter("message")+"<br/>");

%>

</body>

</html>

相关推荐
CN.LG几秒前
浅谈Python之协程
开发语言·python
国中之林15 分钟前
【C++ Primer Plus习题】17.5
开发语言·c++·学习·刷题
砖业洋__20 分钟前
Spring高手之路24——事务类型及传播行为实战指南
java·spring·事务·nested·事务传播行为
黄俊懿21 分钟前
【深入理解SpringCloud微服务】了解微服务的熔断、限流、降级,手写实现一个微服务熔断限流器
java·分布式·后端·spring cloud·微服务·架构·手写源码
追风筝的Coder25 分钟前
泛微开发修炼之旅--44用友U9与ecology对接方案及源码
java
CrazyZ12632 分钟前
c++primer 第八章函数编程答案
开发语言·c++·笔记·学习·算法
鱟鲥鳚35 分钟前
对象关系映射ORM
java
Squirrel-Htzsl42 分钟前
C++_多态
开发语言·c++
aristo_boyunv1 小时前
【线程池】ThreadPoolExecutor应用
java·线程池·并发
码力码力我爱你1 小时前
C HTML格式解析与生成之gumbo
c语言·开发语言·html