国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JSP > 正文

純JSP實(shí)現(xiàn)的簡單登錄示例

2024-09-05 00:22:36
字體:
供稿:網(wǎng)友

本文實(shí)例講述了純JSP實(shí)現(xiàn)的簡單登錄的方法。分享給大家供大家參考,具體如下:

文件共有四個(gè)web.xml、login.jsp、logout.jsp、welcome.jsp四個(gè)文件

測試環(huán)境:Tomcat 6.0.x

假設(shè)項(xiàng)目名稱是LoginSample,我的目錄結(jié)構(gòu)是這樣的

.../webapps/LoginSample/WEB-INF/web.xml
.../webapps/LoginSample/login.jsp
.../webapps/LoginSample/logout.jsp
.../webapps/LoginSample/welcome.jsp

web.xml源碼清單:

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"version="2.4">  <welcome-file-list>    <welcome-file>welcome.jsp</welcome-file>  </welcome-file-list></web-app>

login.jsp源碼清單:

<%@ page contentType="text/html;charset=UTF-8" %><html> <head>  <title>JSP簡單登錄實(shí)例</title> </head> <body> <h2>請(qǐng)登錄</h2> <form method="POST" >  Login Name: <input type="text" name="Name"><br>  Login Password: <input type="text" name="Password" ><br>  <input type="submit" value="Send"><br> <form> <%   if (request.getParameter("Name") != null       && request.getParameter("Password") != null) {     String Name = request.getParameter("Name");     String Password = request.getParameter("Password");     if (Name.equals("a") && Password.equals("a")) {       session.setAttribute("Login", "OK");       session.setAttribute("myCount", new Integer(1));       response.sendRedirect("welcome.jsp");     }     else {       %>       登錄失敗:用戶名或密碼不正確~       <%     }   }%> </body></html>

logout.jsp源碼清單:

<%@ page contentType="text/html;charset=UTF-8" %><html> <%  session.setAttribute("Login", ""); %> <body> <h2>你已經(jīng)退出登錄</h2> </body></html>

welcome.jsp源碼清單:

<%@ page contentType="text/html" pageEncoding="UTF-8" import="java.util.*"%><html> <body> <h2>歡迎頁面(測試session)</h2> <% String Login = (String)session.getAttribute("Login"); int   nCount=0; if (Login != null && Login.equals("OK")) {   Integer myCount = (Integer)session.getAttribute("myCount");   if(myCount!=null)   {     nCount = myCount.intValue();     nCount = nCount + 1;     session.setAttribute("myCount",new Integer(nCount));   }   %>   登錄成功,myCount=<%=nCount%></br>   <input type=button value="退出" onclick="javascript:location.href='logout.jsp'">   <% } else {%>   <jsp:forward page="login.jsp"/><%  }  %>  </body></html>

希望本文所述對(duì)大家JSP程序設(shè)計(jì)有所幫助。


注:相關(guān)教程知識(shí)閱讀請(qǐng)移步到JSP教程頻道。
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 恩施市| 六盘水市| 吉木乃县| 桐梓县| 清涧县| 泉州市| 库车县| 吉隆县| 佛教| 广安市| 清河县| 东乡族自治县| 景泰县| 巴彦县| 灌云县| 三河市| 定襄县| 奉化市| 西和县| 尼木县| 全州县| 四平市| 巍山| 曲阳县| 青海省| 靖安县| 成武县| 长岛县| 潜山县| 新闻| 金寨县| 绥德县| 宁远县| 酉阳| 綦江县| 宁安市| 阿巴嘎旗| 秦皇岛市| 金堂县| 永嘉县| 富阳市|