session对象练习
Posted jhmll
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了session对象练习相关的知识,希望对你有一定的参考价值。
<body> <h2 class="a">欢迎来到新闻发布系统</h2> <form action="denglu.jsp" > <button >登录</button></form> <form action="zhuce.jsp" class="b"> <button>注册</button> </form> </body>
<body> <h2>注册页面</h2> <form action="denglu.jsp" method="get"> 账户:<input type="text" name="zzhanghao" ><br> 密码:<input type="password" name="zmima"> <input type="submit" value="注册"> </form> <br> </body> zhuce.jsp
<body> <h2>登录页面</h2> <% String zzh=request.getParameter("zzhanghao"); String zmm=request.getParameter("zmima"); session.setAttribute("zzzhanghao", zzh); session.setAttribute("zzmima", zmm); %> <form action="dchuli.jsp" method="get"> 账户:<input type="text" name="dzhanghao"><br> 密码:<input type="password" name="dmima"> <input type="submit" value="登录"></form> <br> </body> denglu.jsp
//登录判断页面 <body> <% String dzh=request.getParameter("dzhanghao"); String dmm=request.getParameter("dmima"); session.setAttribute("ddzhanghao", dzh); session.setAttribute("ddmima", dmm); String zzzhanghao=(String)session.getAttribute("zzzhanghao"); String zzmima=(String)session.getAttribute("zzmima"); String ddzhanghao=(String)session.getAttribute("ddzhanghao"); String ddmima=(String)session.getAttribute("ddmima"); if(ddzhanghao==null||ddmima==null){ ddzhanghao="orr"; ddmima="orr"; } if(zzzhanghao==null||zzmima==null){ zzzhanghao="eorr"; zzmima="eorr"; } if(zzzhanghao.equals(ddzhanghao)&&zzmima.equals(ddmima)){ if(zzzhanghao.equals("admin")){ out.println("后台操作页面"+"</br>"); out.println("管理员信息"+"</br>");out.print("管理员账号"+ddzhanghao+"登录密码"+ddmima); }else{ request.getRequestDispatcher("index2.jsp").forward(request, response); } }else{ //out.print(dzhanghao); String a=(String)session.getAttribute("zzzhanghao"); String b=(String)session.getAttribute("zzmima"); request.getRequestDispatcher("denglu.jsp").forward(request, response); } %> <!-- 注册账号<%=zzzhanghao %>注册密码<%=zzmima %><br> 登录账号<%=ddzhanghao %> 登录密码<%=ddmima %> --> <br> </body> dchuli.jsp
<!-- 新闻页面 --> <body> <form action="pyan.jsp"> 最新新闻<br><br>评论:<input type="text" name="pinglun"><input type="submit" value="提交评论"><br></form> <br> </body>
<!-- 评论发表 --> <body> <% String py=request.getParameter("pinglun"); session.setAttribute("pyanzheng", py); String yh=(String)session.getAttribute("ddzhanghao"); String pl=(String)session.getAttribute("pyanzheng"); %> <form action=""> 最新新闻<br><br>评论:<input type="text"><input type="submit" value="提交评论"><br> 用户:<%= yh%>说:<%= pl%> </form> <br> </body> pyan.jsp