脚本宝典收集整理的这篇文章主要介绍了JSP第六次作业,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
1.登陆输入用户名密码,判断用户名和密码相同,登陆成功,session中保存用户的用户名,进入主页main.jsp,主页有一个退出按钮,点击,回到登陆页login.jsp。要求:退出登录后,如果在浏览器直接输入主页main.jsp,访问不了,直接跳到登陆页。
2.购物车和上一题一起,在main.jsp中做一个购物车,里面显示3个商品名和价格 每一个后面有一个加入购物车按钮,main.jsp中有一个按钮(或者超链接)可以显示购物车。(选作:在购物车中加删除按钮删除商品)
<body bgcolor="#ffc0cb"> <form name="form" action="<%=request.getContextPath()%>/week8/dologin.jsp" method="post"> 用户名:<input type="text" name="uname" minlength="1" maxlenghth="10"><br> 密 码:<input type="password" name="upwd" minlength="1" maxlenghth="10"><br> <input type="submit" value="登录" ><br> </form> </body>
<body bgcolor="#ffc0cb"> <h1>登陆成功!</h1> <% String uname = (String) session.getAttribute("uname"); if (uname == null) response.sendRedirect("login.jsp"); %> <table> <form action="<%=request.getContextPath()%>/week8/cart.jsp" method="post"> <tr> 商品:<br></tr> <tr>蝴蝶蓝宝石 8.3w<input type="radio" name="item" value="蝴蝶蓝宝石">加入购物车<br></tr> <tr>薄 荷 10w <input type="radio" name="item" value="薄荷"> 加入购物车<br></tr> <tr>野 荷 5 w <input type="radio" name="item" value="野荷"> 加入购物车<br></tr> <tr><input type="submit" value="加入购物车"></tr> </form> <form action="<%=request.getContextPath()%>/week8/login.jsp" method="post"> <tr colspan="5"> <input type="submit" value="退出登录"> </tr> </form> </table> </body>
<body bgcolor="#ffc0cb"> <% request.setCharacterEncoding("utf-8"); String itemName[]=request.getParameterValues("item"); if(itemName==null){ out.print("购物车为空!请返回添加商品。"); } else{ for(int i=0;i<itemName.length;i++){ out.print("("+(i+1)+")"+itemName[i]+"<br>"); } } %> </body>
<body bgcolor="#ffc0cb"> <% request.setCharacterEncoding("utf-8"); String uname=request.getParameter("uname"); String upwd=request.getParameter("upwd"); if(uname.equals(upwd)){ session.setAttribute("uname", uname); request.getRequestDispatcher("main.jsp").forward(request,response); }else{ request.getRequestDispatcher("no.jsp").forward(request,response); } %> </body>
<body bgcolor="#ffc0cb"> <h1>账户或密码错误,登陆失败!</h1> <%response.setHeader("refresh", "5;url=login.jsp");%> </body>
以上是脚本宝典为你收集整理的JSP第六次作业全部内容,希望文章能够帮你解决JSP第六次作业所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。