第七周作业
1.教材P78-79 例4-9
<html> <head> <base href="<%=basePath%>"> </head> <body> <body bgcolor = #ffccff> <% double price =98.78; %> <p style = "font-family:宋体;font-size:36;color:blue"> 商品编号 A1001,价格8765 <a href = "receive.jsp?id=A1001&price=8765">购买</a><br> 商品编号A1002,价格<%=price %> <a href = "receive.jsp?id=A1002&price=<%=price%>">购买</a> </p> </body> </html>
<html> <head> <base href="<%=basePath%>"> </head> <body> <body bgcolor = #EEEEFF> <p style = "font-family:宋体;font-size:36;color:blue"> <% String id = request.getParameter("id"); String price = request.getParameter("price"); %> <b>商品编号:<%=id%><br> 商品价格:<%=price %> </p> </body> </html>
2.教材P97 实验2
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <body bgcolor=#ffccff> <form action="jisuan.jsp" method=post name=form> <p style="font-family:宋体;font-size:18;color:blue"> 输入运算数,选择运算符号:<br> <input type=text name="numberOne" size=6/> <select name="operator"> <option selected = "value" value="+">加 <option value="-">减 <option value="*">乘 <option value="/">除 </select> <input type=text name="numberTwo"size=6/> <br><input type="submit" value="提交"/> </form> </body> </html>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <body bgcolor = cyan> <p style="font-family:宋体;font-size:18;color:black"> <% String numberOne = request.getParameter("numberOne"); String numberTwo = request.getParameter("numberTwo"); String operator = request.getParameter("operator") ; if(numberOne==null||numberOne.length()==0){ response.sendRedirect("input.jsp"); return; } else if(numberTwo==null||numberTwo.length()==0){ response.sendRedirect("input.jsp"); return; } try{ double a=Double.parseDouble(numberOne); double b=Double.parseDouble(numberTwo); double r=0; if(operator.equals("+")) r=a+b; else if(operator.equals("-")) r=a-b; else if(operator.equals("*")) r=a*b; else if(operator.equals("/")) r=a/b; out.print(a+""+operator+""+b+"="+r); } catch(Exception e){ out.println("请输入数字字符"); } %> </body> </html>
3.制作一个登陆表单,输入账号和密码,如果账号密码相同,跳转到“登录成功”页面,否则跳转到“登录失败”页面。(加上JS非空验证)(选做,加验证码)
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <html> <body> <script type="text/javascript"> function validate() { if (loginForm.account.value == "") { alert("账号不能为空!"); return; } else if (loginForm.password.value == "") { alert("密码不能为空!"); return; } loginForm.submit(); } </script> <form action="zhanghao.jsp" name="loginForm" method="post"> 账号:<input type="text" name="account" placeholder="请输入账号"/><br> 密码:<input type="password" name="password" placeholder="请输入密码"/><br> <input type="button" value="登录"onClick="validate()"> </form> </body> </html>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <html> <body> <% String account=request.getParameter("account"); String password=request.getParameter("password"); if(account.equals(password)){ request.getRequestDispatcher("ok.jsp").forward(request,response); } else{ response.sendRedirect("no.jsp"); } %> </body> </html>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <% request.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8"); %> <html> <body> 登陆成功! </body> </html>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <% request.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8"); %> <html> <body> 登陆失败! </body> </html>
5.在页面1的表单内输人一个数字N,提交,能够在另一个页面打印N个“欢迎”字符串。
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> </head> <body> 请输入一个数字 : <form action="ok.jsp" method=post> <input type="text" name="shu" value=""> <input type="submit" value="确定"> </form> </body> </html>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <body> <% request.setCharacterEncoding("utf-8"); String shu=request.getParameter("shu"); double j=Double.parseDouble(shu); for(int i=1;i<j;i++){ out.print("欢迎"+"<br>"); } %> </body> </html>
6.在页面1中输入账号和密码,进行登录,如果账号和密码相同,则认为成功登录到页面2,在页面2中显示一个文本框输人用户姓名,输人之后提交,在页面3中显示用户的账号和姓名。(转发)request.getRequestDispacher.....forward
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <body> <script type="text/javascript"> function validate() { if (loginForm.id.value == "") { alert("账号不能为空"); return; } else if (loginForm.mi.value == "") { alert("密码不能为空"); return; } loginForm.submit(); } </script> <form name="loginForm" action="panduan.jsp" method="post"> 请输入相同的账号密码 <br> 账号: <input type="text" name="id" value="请输入账号"> <br> 密码: <input type="password" name="mi" value="请输入密码"> <br> <input type="button" name="admir" value="登录" onClick="validate()"> </form> </body> </html>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <body> 登录失败! </body> </html>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <body> <% request.setCharacterEncoding("utf-8"); String id = request.getParameter("id"); %> <form action="zuihou.jsp" method="post"> 请输入姓名: <input type="text" name="xingming" value=""> <input type="submit" value="确定"> <input type="hidden" name="id" value="<%=id%>" /> </form> </body> </html>
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> </head> <body> <% request.setCharacterEncoding("utf-8"); String id = request.getParameter("id"); String mi = request.getParameter("mi"); if (id.equalsIgnoreCase(mi)) { request.getRequestDispatcher("ok.jsp").forward(request, response); } else { request.getRequestDispatcher("no.jsp").forward(request, response); } %> </body> </html>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <body> <% request.setCharacterEncoding("utf-8"); String id = request.getParameter("id"); String name = request.getParameter("xingming"); out.print("用户姓名:" + name + "<br>" + "用户账号:" + zh); %> </body> </html>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人