jsp实现登陆界面代码(jsp简单登录界面代码)

发布时间:2023-12-08

jsp实现登陆界面代码(jsp简单登录界面代码)

更新:2022-11-10 07:26

本文目录一览:

  1. jsp 登陆界面的代码
  2. 编写用户注册于登录的JSP页面的全部程序代码
  3. 求JSP登陆界面代码
  4. jsp登陆界面源代码
  5. jsp实现简单的登录界面

jsp 登陆界面的代码

登录判断的页面代码:

<%@ page contentType="text/html; charset=gb2312"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.util.*"%>
<%@ include file="conn.jsp"%>
<%
request.setCharacterEncoding("gb2312");
Statement stat=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String name=request.getParameter("name");
String password=request.getParameter("password");
ResultSet rs=stat.executeQuery("select * from sjb where name='"+name+"'and pass='"+password+"'");
%>
<%if(rs.next()){ %>
<%String shenfen=rs.getString(6);%>
<%session.setAttribute("name",name);%>
<%response.sendRedirect("index1.jsp");%>
<%}else{%>
<%out.print("帐号密码输入错误");%>
<a href="index1.jsp">点击返回</a>
<%}%>

登录输入时的代码:

<form action="login.jsp" method="post" name="form1" class="STYLE1" id="form1">
  帐号
  <label>
    <input name="name" type="text" id="name" tabindex="1" size="13" maxlength="13" />
  </label>
  <a href="regedit.jsp">注册</a>
  密码
  <label>
    <input name="password" type="password" id="password" size="13" maxlength="13" />
  </label>
  <a href="forget.jsp">忘记</a>
  <label>
    <input type="submit" name="Submit" value="确定" />
  </label>
  <label>
    <input type="reset" name="Submit2" value="重填" />
  </label>
</form>

编写用户注册于登录的JSP页面的全部程序代码

3个jsp文件,第一个是login.jsp,第二个是judge.jsp,第三个是afterLogin.jsp。

login.jsp

<%@ page language="java" contentType="text/html; charset=GB18030" pageEncoding="GB18030"%>
<%@ page import="java.util.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <title>登录页面</title>
</head>
<body>
  <form name="loginForm" method="post" action="judgeUser.jsp">
    <table>
      <tr>
        <td>用户名:<input type="text" name="userName" id="userName"/></td>
      </tr>
      <tr>
        <td>密码:<input type="password" name="password" id="password"/></td>
      </tr>
      <tr>
        <td>
          <input type="submit" value="登录" style="background-color:pink" />
          <input type="reset" value="重置" style="background-color:red"/>
        </td>
      </tr>
    </table>
  </form>
</body>
</html>

judge.jsp

<%@ page language="java" contentType="text/html; charset=GB18030" pageEncoding="GB18030"%>
<%@ page import="java.util.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <title>身份验证</title>
</head>
<body>
<%
request.setCharacterEncoding("GB18030");
String name = request.getParameter("userName");
String password = request.getParameter("password");
if(name.equals("abc") && password.equals("123")) {
%>
<jsp:forward page="afterLogin.jsp">
  <jsp:param name="userName" value="<%=name%>"/>
</jsp:forward>
<%
} else {
%>
<jsp:forward page="login.jsp"/>
<%
}
%>
</body>
</html>

afterLogin.jsp

<%@ page language="java" contentType="text/html; charset=GB18030" pageEncoding="GB18030"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <title>登录成功</title>
</head>
<body>
<%
request.setCharacterEncoding("GB18030");
String name = request.getParameter("userName");
out.println("欢迎你:" + name);
%>
</body>
</html>

求JSP登陆界面代码

给你提供一下思路吧:

  1. 输入界面:输入用户名和密码。
  2. 处理界面:获取提交过来的数据(用户名和密码),然后进行验证。然后填写正确时,跳转成功的界面;不正确时,跳转失败的界面。
  3. 创建成功界面与失败界面。

登录界面:

<%@ page language="java" pageEncoding="GBK"%>
<html>
<head><title>登录界面</title></head>
<body>
  <div align="center">
    <form action="validate.jsp" method="post">
      用户名:<input type="text" name="myName"><br>
      密码:<input type="password" name="myPass"><br>
      <input type="submit" value="登录"/>
    </form>
  </div>
</body>
</html>

登录验证界面:

<%@ page language="java" pageEncoding="GBK"%>
<%
//处理中文乱码
request.setCharacterEncoding("GBK");
//获取提交的元素
String name = request.getParameter("myName");
String pass = request.getParameter("myPass");
//业务处理
if("admin".equals(name) && "admin".equals(pass)){
  response.sendRedirect("yes.jsp");
} else {
  response.sendRedirect("no.jsp");
}
%>

成功界面:

<%@ page language="java" pageEncoding="GBK"%>
<html>
<head><title>成功界面</title></head>
<body>登录成功!</body>
</html>

jsp登陆界面源代码

1、login.jsp文件

<%@ page language="java" contentType="text/html; charset=GB18030" pageEncoding="GB18030"%>
<%@ page import="java.util.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <title>登录页面</title>
</head>
<body>
  <form name="loginForm" method="post" action="judgeUser.jsp">
    <table>
      <tr>
        <td>用户名:<input type="text" name="userName" id="userName"/></td>
      </tr>
      <tr>
        <td>密码:<input type="password" name="password" id="password"/></td>
      </tr>
      <tr>
        <td>
          <input type="submit" value="登录" style="background-color:pink" />
          <input type="reset" value="重置" style="background-color:red"/>
        </td>
      </tr>
    </table>
  </form>
</body>
</html>

2、judge.jsp文件

<%@ page language="java" contentType="text/html; charset=GB18030" pageEncoding="GB18030"%>
<%@ page import="java.util.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <title>身份验证</title>
</head>
<body>
<%
request.setCharacterEncoding("GB18030");
String name = request.getParameter("userName");
String password = request.getParameter("password");
if(name.equals("abc") && password.equals("123")) {
%>
<jsp:forward page="afterLogin.jsp">
  <jsp:param name="userName" value="<%=name%>"/>
</jsp:forward>
<%
} else {
%>
<jsp:forward page="login.jsp"/>
<%
}
%>
</body>
</html>

3、afterLogin.jsp文件

<%@ page language="java" contentType="text/html; charset=GB18030" pageEncoding="GB18030"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <title>登录成功</title>
</head>
<body>
<%
request.setCharacterEncoding("GB18030");
String name = request.getParameter("userName");
out.println("欢迎你:" + name);
%>
</body>
</html>

扩展资料:

java web登录界面源代码:

1、Data_uil.java文件
import java.sql.*;
public class Data_uil {
  public Connection getConnection() {
    try {
      Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
    } catch(ClassNotFoundException e) {
      e.printStackTrace();
    }
    String user="***";
    String password="***";
    String url="jdbc:sqlserver://127.0.0.1:1433;DatabaseName=***";
    Connection con=null;
    try {
      con=DriverManager.getConnection(url,user,password);
    } catch(SQLException e) {
      e.printStackTrace();
    }
    return con;
  }
  public String selectPassword(String username) {
    Connection connection=getConnection();
    String sql="select *from login where username=?";
    PreparedStatement preparedStatement=null;
    ResultSet result=null;
    String password=null;
    try {
      preparedStatement=connection.prepareStatement(sql);
      preparedStatement.setString(1,username);
      result=preparedStatement.executeQuery();
      if(result.next())
        password=result.getString("password");
    } catch(SQLException e) {
      e.printStackTrace();
    } finally {
      close(preparedStatement);
      close(result);
      close(connection);
    }
    System.out.println("找到的数据库密码为:"+password);
    return password;
  }
  public void close (Connection con) {
    try {
      if(con!=null) {
        con.close();
      }
    } catch(SQLException e) {
      e.printStackTrace();
    }
  }
  public void close (PreparedStatement preparedStatement) {
    try {
      if(preparedStatement!=null) {
        preparedStatement.close();
      }
    } catch(SQLException e) {
      e.printStackTrace();
    }
  }
  public void close(ResultSet resultSet) {
    try {
      if(resultSet!=null) {
        resultSet.close();
      }
    } catch(SQLException e) {
      e.printStackTrace();
    }
  }
}
2、login_check.jsp文件
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" ""
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <title>验证用户密码</title>
</head>
<body>
  <jsp:useBean id="util" class="util.Data_uil" scope="page" />
  <%
  String username=(String)request.getParameter("username");
  String password=(String)request.getParameter("password");
  if(username==null||"".equals(username)) {
    out.print("<script language='javaScript'> alert('用户名不能为空');</script>");
    response.setHeader("refresh", "0;url=user_login.jsp");
  } else {
    System.out.println("输入的用户名:"+username);
    String passwordInDataBase=util.selectPassword(username);
    System.out.println("密码:"+passwordInDataBase);
    if(passwordInDataBase==null||"".equals(passwordInDataBase)) {
      out.print("<script language='javaScript'> alert('用户名不存在');</script>");
      response.setHeader("refresh", "0;url=user_login.jsp");
    } else if(passwordInDataBase.equals(password)) {
      out.print("<script language='javaScript'> alert('登录成功');</script>");
      response.setHeader("refresh", "0;url=loginSucces.jsp");
    } else {
      out.print("<script language='javaScript'> alert('密码错误');</script>");
      response.setHeader("refresh", "0;url=user_login.jsp");
    }
  }
  %>
</body>
</html>
3、loginSucces.jsp文件
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" ""
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  <title>Insert title here</title>
</head>
<body>
  <hr size="10" width="26%" align="left" color="green">
  <font size="6" color="red">登录成功</font>
  <hr size="10" width="26%" align="left" color="green">
</body>
</html>
4、user_login.jsp文件
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" ""
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  <title>登录界面</title>
</head>
<body background="C:\Users\win8\workspace\Login\image\9dcbdc339e72a5663b5c289fb5573c13_10.jpg">
  <center>
    <br><br><br><br><br><br>
    <h1 style="color:yellow">Login</h1>
    <br>
    <form name="loginForm" action="login_check.jsp" method="post">
      <table Border="0">
        <tr>
          <td>账号</td>
          <td><input type="text" name="username"/></td>
        </tr>
        <tr>
          <td>密码</td>
          <td><input type="password" name="password"></td>
        </tr>
      </table>
      <br>
      <input type="submit" value="登录" style="color:#BC8F8F">
    </form>
  </center>
</body>
</html>

jsp实现简单的登录界面

index.jsp是本页面:

<html>
<body>
  <form action="manager.jsp" name="form1" method="post">
    <input type="text" name="name">
    <input type="password" name="password">
    <input type="submit" value="登录" name="submit"> 管理
  </form>
</body>
</html>

manager.jsp是要登录的页面:

<%
String name=request.getParameter("name");
String password=request.getParameter("password");
if(name.equals("cxh") && password.equals("11011")) {
%>
<jsp:forward page="manager.jsp" />
<%
} else {
%>
<jsp:forward page="index.jsp" />
<%
}
%>

这样才是提交嘛~~~你试试~