分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 前端开发

基于jsp+servlet的登录用户界面验证

发布时间:2023-09-06 01:24责任编辑:苏小强关键词:jsjsp
 ?1 login.jsp ?2 ??3 <%@page contentType="text/html" ?pageEncoding="UTF-8"%> ?4 <% ?5 String path = request.getContextPath(); ?6 String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; ?7 %> ?8 ??9 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 10 <html> 11 ??<head> 12 ????<base href="<%=basePath%>"> 13 ?????14 ????<title>用户登录界面</title> 15 ?????16 ????<meta http-equiv="pragma" content="no-cache"> 17 ????<meta http-equiv="cache-control" content="no-cache"> 18 ????<meta http-equiv="expires" content="0"> ????19 ????<meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> 20 ????<meta http-equiv="description" content="This is my page"> 21 ????<!-- 22 ????<link rel="stylesheet" type="text/css" href="styles.css"> 23 ????--> 24 ?25 ??</head> 26 ???27 ??<body> 28 ???<form action="loginCheck" method="post"> 29 ???用户名: <input type="text" name="name"><br><br> 30 ???密码: ??<input type="password" ?name="password"><br><br> 31 ???<input type="submit" ?value="确 ?认">&nbsp;&nbsp;&nbsp;&nbsp; 32 ???<input type="reset" ??value="取 ?消">&nbsp;&nbsp;&nbsp;&nbsp; 33 ???</form> 34 ??</body> 35 </html> 36 ?37 ?38 LoginCheckServlet.java 39 ?40 package servlets; 41 ?42 import java.io.IOException; 43 //import java.io.PrintWriter; 44 ?45 import javax.servlet.ServletException; 46 import javax.servlet.http.HttpServlet; 47 import javax.servlet.http.HttpServletRequest; 48 import javax.servlet.http.HttpServletResponse; 49 ?50 public class LoginCheckServlet extends HttpServlet { 51 ?52 ?53 ????/** 54 ?????* ?55 ?????*/ 56 ????private static final long serialVersionUID = 1L; 57 ?58 ????public void doPost(HttpServletRequest request, HttpServletResponse response) 59 ????????????throws ServletException, IOException { 60 String Name=request.getParameter("name"); 61 String Password=request.getParameter("password"); 62 String info=""; 63 if(("abc".equals(Name))&&("123".equals(Password))){ 64 ????info="欢迎你的登录"+Name+"!";} 65 ????else 66 ????{info="登陆失败!";} 67 request.setAttribute("outputMessage",info); 68 request.getRequestDispatcher("info.jsp").forward(request,response); 69 } 70 ????????//response.setContentType("text/html"); 71 ?????????72 ?????73 ????} 74 ?75 info.jsp 76 ?77 <%@ page ?pageEncoding="UTF-8"%> 78 <% 79 String path = request.getContextPath(); 80 String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; 81 %> 82 ?83 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 84 <html> 85 ??<head> 86 ????<base href="<%=basePath%>"> 87 ?????88 ????<title>显示页面</title> 89 ?????90 ????<meta http-equiv="pragma" content="no-cache"> 91 ????<meta http-equiv="cache-control" content="no-cache"> 92 ????<meta http-equiv="expires" content="0"> ????93 ????<meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> 94 ????<meta http-equiv="description" content="This is my page"> 95 ????<!-- 96 ????<link rel="stylesheet" type="text/css" href="styles.css"> 97 ????--> 98 ?99 ??</head>100 ??101 ??<body>102 ???<%=request.getAttribute("outputMessage") %>103 ??</body>104 </html>

基于jsp+servlet的登录用户界面验证

原文地址:http://www.cnblogs.com/jun699701/p/7816677.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved