日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

简单WEB登录页面代码实现

發(fā)布時(shí)間:2023/12/31 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 简单WEB登录页面代码实现 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

longin.html:登錄頁面,此處action引用**/**類型的地址,JSP可以用${ pageContext.request.contextPath }/LS

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> </head><body><form action="/lianxiti/LS",method="post">用戶名: <input name="username" type="text" /><br/>密碼:<input name="password" type="password" /><br/> <input type="submit" value="提交" id="bt" /></form></body>

LoginServlet.java用戶和前臺(tái)WEB頁面數(shù)據(jù)進(jìn)行交互

package it.tongyou.web.servlet;import java.io.IOException; import java.io.PrintWriter;import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;public class LoginServlet extends HttpServlet {public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {//亂碼解決response.setContentType("text/html;charset-utf-8");//獲取頁面?zhèn)鬟^來的數(shù)據(jù)String username=request.getParameter("username");String password=request.getParameter("password");//判斷賬號(hào)密碼if(("xm").equals(username) && ("123").equals(password)){response.sendRedirect("/lianxiti/success.html");}else{response.sendRedirect("/liantixi/longin.html");}}public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {doGet(request, response);} }

web.xml應(yīng)用路徑配置/LS和longin.html引用地址一定要一樣,因?yàn)榇颂幮枰裌EB頁面的數(shù)據(jù)提交到對(duì)應(yīng)的servlet中;

<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"><!-- 頁面WEB跳轉(zhuǎn)servlet層 --><servlet><servlet-name>LoginServlet</servlet-name><servlet-class>it.tongyou.web.servlet.LoginServlet</servlet-class></servlet><servlet-mapping><servlet-name>LoginServlet</servlet-name><url-pattern>/LS</url-pattern></servlet-mapping><!-- 打開項(xiàng)目優(yōu)先展示頁面 --> <welcome-file-list><welcome-file>longin.html</welcome-file></welcome-file-list> </web-app>

成功后跳到success.html頁面

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> </head><body>成功登錄</body> </html>

總結(jié)

以上是生活随笔為你收集整理的简单WEB登录页面代码实现的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。