- 两个数求和
- 用javascript实现。
- 输入、处理、输出用同一个页面(自己处理自己)。
- 输入1.jsp,处理和输出2.jsp。
(4)输入1.jsp,处理2.jsp,处理完转回1.jsp显示结果。
(5)输入1.jsp,处理2.jsp,输出3.jsp。
- 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>
- 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>
- 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>
- 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>
- 设计一个用户注册表单,用户填写完并提交后输出用户填写的信息。如图所示:
- 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>
- 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>
- 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>