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>

相关推荐
酷爱码29 分钟前
如何通过python连接hive,并对里面的表进行增删改查操作
开发语言·hive·python
画个大饼31 分钟前
Go语言实战:快速搭建完整的用户认证系统
开发语言·后端·golang
喵先生!2 小时前
C++中的vector和list的区别与适用场景
开发语言·c++
Nelson_hehe2 小时前
Java基础第四章、面向对象
java·语法基础·面向对象程序设计
Thomas_YXQ2 小时前
Unity3D Lua集成技术指南
java·开发语言·驱动开发·junit·全文检索·lua·unity3d
xMathematics3 小时前
计算机图形学实践:结合Qt和OpenGL实现绘制彩色三角形
开发语言·c++·qt·计算机图形学·cmake·opengl
ShiinaMashirol3 小时前
代码随想录打卡|Day27(合并区间、单调递增的数字、监控二叉树)
java·算法
东阳马生架构5 小时前
Nacos简介—3.Nacos的配置简介
java
yuanManGan5 小时前
C++入门小馆: 深入了解STLlist
开发语言·c++
北极的企鹅885 小时前
XML内容解析成实体类
xml·java·开发语言