您的位置:首页 > Web前端 > JavaScript

初学者jsp中登录界面判断是否登陆成功

2018-03-25 14:28 405 查看
首先先写登录界面:
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'Login.jsp' starting page</title>
    
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">    
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

  </head>
  
  <body>
 <h1 align="center">用户登录</h1>
 <form action="gain.jsp" method="post" name="loginForm">
<table align="center">
<tr>
<td>用户名:</td>
<td><input type="text" name="username" value="请你输入用户名"></td>
</tr>
<tr>
<td>密码:</td>
<td><input type="password" name="password"></td>
</tr>
      <tr>
      <td></td>
      <td align="center"><input type="submit" onClick="validate" value="提交"></td>
      </tr>
</table>
 </form>
  </body>
</html>
继续写出判断界面 首先给定一个用户名和密码进而进行判断
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'gain.jsp' starting page</title>
    
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">    
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

  </head>
  
  <body>
  <%
  String name="张三";
  String psw="123456";
  request.setCharacterEncoding("gb2312");
  String username=request.getParameter("username");
  String password=request.getParameter("password");
  if(username.equals(name)&&password.equals(psw)){
   out.println("登录成功");
  
  }else{
  out.println("您的账号或者密码错误");
  } 
   %>
  </body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐