jsp示例-response页面重定向
生活随笔
收集整理的這篇文章主要介紹了
jsp示例-response页面重定向
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
用戶輸入用戶名和密碼,如果用戶名和密碼分別是admin 和123,就重定向到success.jsp頁面,否則重定向到登錄頁面。
index.jsp:
<html> <body> 登錄<br> <form action="next.jsp" method="post"> 用戶名:<input type="text" name="username"> <br> 密??碼:<input type="password" name="password"> <br> <input type="submit" value="登錄"> </form> </body> </html>next.jsp: <% String username=request.getParameter("username"); String password=request.getParameter("password"); if("admin".equals(username)&&"123".equals(password)) {response.sendRedirect("success.jsp");}else{response.sendRedirect("index.jsp");}%>
success.jsp: <html> <body>Login success</body> </html>
運行index.jsp的結(jié)果:
輸入用戶名admin,密碼123后,頁面重定向到success.jsp:
如果輸入用戶名和密碼不對,重定向回index.jsp頁面。
總結(jié)
以上是生活随笔為你收集整理的jsp示例-response页面重定向的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 记最近分析的一个锁屏幕病毒
- 下一篇: 在java中对null的理解