jsp编写用户登录界面,jsp做登录界面

本文目录一览:

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

tdinput 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”)) {

3、afterLogin.jsp文件

%

jsp:forward page=”afterLogin.jsp”

jsp:param name=”userName” value=”%=name%”/

/jsp:forward

%

}

else {

%

jsp:forward page=”login.jsp”/

%

}

%

/body

/html

%@ 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″

titleInsert 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

brbrbrbrbrbr

h1 style=”color:yellow”Login/h1

br

form name=”loginForm” action=”login_check.jsp” method=”post” 

table Border=”0″

tr

td账号/td

tdinput type=”text” name=”username”/td

/tr

tr

td密码/td

tdinput type=”password” name=”password”

/td

/tr

/table

br

input type=”submit” value=”登录” style=”color:#BC8F8F”

/form

/center

/body

/html

用jsp怎样做一个用户登录界面

//jsp文件,登录界面

%@page pageEncoding=”utf-8″ contentType=”text/html; charset = utf-8″%

body

h1Register/h1

hr /

form action=”login” method=”post”

用户名:š

input type=”text” name=”username” id=”text” /

密 码:š

input type=”password” name=”pwd” id=”text” //

input type=”submit” value=”登录” id=”button” /

/form

/body

//这是server文件,web.xml部署名字login

import java.io.IOException;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import javax.servlet.http.HttpSession;

public class AddUser extends HttpServlet {

public void service(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

response.setContentType(“text/html;charset=utf-8”);

request.setCharacterEncoding(“utf-8”);

String username=request.getParameter(“username”);

String pwd=request.getParameter(“pwd”);

try{

if(username.equals(”name”)pwd.equals(“pwd”) ){

    system.out.print(“登录成功”);

}else{

    system.out.print(“error”);

}

}catch(Exception e){

e.printStackTrace();

}

}

}

简单的登录界面,不需要数据库,如果要链接数据库就要判断很多了

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

3个jsp文件,第一个是login.jsp,第二个是judge.jsp,第三个是afterLogin.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

tdinput type=”submit” value=”登录” style=”background-color:pink” input type=”reset” value=”重置” style=”background-color:red”/td

/tr

/table

/form

/body

/html

%@ 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

%@ 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编写一个很简单的登陆页面

login.JSP

注: 由于时间仓促,程序可能有细小的问题!但绝对可以满足你的需要了!如果你知道JSP什么原理;那么小的问题不是什么问题了! 共同学习~~~

%@ page contentType = “text/html;charset=GB2312” %

%@ page import = “java.sql.*” %

html

head

title/title

/head

body bgcolor=LightBlue

div align=”center”

br

H1欢迎光临企业办公平台/H1

form name=”form1″ method=”post” action=”” target=”_self”

table width=”90%”

tr

td width=”50%” height=”30″ align=”right”用户名:/td

td width=”50%” height=”30″ align=”left” input type=”text” name=”UserName”/td

/tr

tr

td width=”50%” height=”30″ align=”right”密码:/td

td width=”50%” height=”30″ align=”left” input type=”password” name=”UserPassword”/td

/tr

td width=”100%” height=”40″ align=”center” colspan=”2″

input type=”submit” name=”sub” value=”登录”  

/td

/tr

/table

/form

/div

% try

{Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);

Connection conn=DriverManager.getConnection(“jdbc:odbc:a”,”root”,”database1″);

Statement stmt = conn.createStatement(

ResultSet.TYPE_SCROLL_INSENSITIVE,

ResultSet.CONCUR_READ_ONLY);

ResultSet rs = null;

String name =new String(request.getParameter(“

UserName”).getBytes(“8859_1”));

String passwd =new String(request.getParameter(“

UserPassword”).getBytes(“8859_1”));

if(String_sql==null)

{

out.println(“登陆名不可以为空”);

out.println(“HR”);

}

else{

String_sql=”select * from student where name =”+name+” and password=”+psword+;

rs=stmt.executeQuery(String_sql)

while(rs.next())

{ out.println(“登陆成功!”);

out.println(“您的用户名是:”+name)

out.println(“您的密码是:”+password);

rs.close();

stmt.close();

conn.close();}

}

Catch( Exception e )

{out.println(“font color=red size=5B”);

out.println(“出错了!”);

out.println(“/B/font”);

}%

/body

/html

jsp下登录界面的方法

关键是sql语句,如果你用jdbc+dao的话就是

select count(当前表的id名比如id) from user where userid= 接收的用户名 and password=接收的密码

然后取得值看该值是否大于0,如果大于0返回一个true值或者直接返回该值,然后判断只要大于0就表示登录成功,和数据库中一样。

你可以通过request跳转,如果登录成功就跳转到登录成功界面,并把你的登录信息保存到session中。否则就直接重定向到登录界面让用户重新登录。

你可以去百度搜索

java jsp 登录 csdn

这样可以从csdn下载相关的登录实例,里面有详细的代码,可以最大程度上帮助你。

原创文章,作者:小蓝,如若转载,请注明出处:https://www.506064.com/n/182236.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
小蓝的头像小蓝
上一篇 2024-11-24 06:19
下一篇 2024-11-24 06:19

相关推荐

  • 如何使用Python将print输出到界面?

    在Python中,print是最常用的调试技巧之一。在编写代码时,您可能需要在屏幕上输出一些值、字符串或结果,以便您可以更好地理解并调试代码。因此,在Python中将print输出…

    编程 2025-04-29
  • Python 如何进入编程界面?

    Python 是一种广泛应用于 Web、游戏、网络爬虫等领域的高级编程语言。Python 虽然易学易用,但还是需要一些工具和步骤来实际编写运行程序。 一、命令行模式 在命令行模式下…

    编程 2025-04-27
  • 为什么web项目的欢迎页必须是jsp?

    在web项目中,欢迎页通常是用户首次访问的页面。而对于这个页面的选择,我们通常会选择jsp作为欢迎页,其原因是什么呢? 一、JSP的优势 JSP与HTML和CSS的结合,可以实现动…

    编程 2025-04-25
  • Python GUI界面详解

    Graphical User Interface (GUI) 即图形用户界面,为用户提供了更加方便直观的操作形式,已经是现代软件的标配。作为一名全能编程开发工程师,掌握Python…

    编程 2025-04-23
  • JSP菜鸟教程详解

    一、JSP介绍 JSP全称Java Server Pages,是一种动态网页技术,它可以将Java代码嵌入HTML页面,实现动态页面的功能。 下面是一个JSP页面的简单示例: He…

    编程 2025-04-12
  • ViewRootImpl:Android应用界面的核心类

    一、ViewRootImpl的作用 ViewRootImpl是Android应用界面的核心类,它的作用是连接View和WindowManager,负责处理输入事件的分发、View的…

    编程 2025-04-12
  • 使用lvglstm32打造高性能嵌入式UI界面

    一、简介 lvglstm32是基于lvgl嵌入式UI库和STM32系列单片机的一款开源项目。它能够实现高性能的图形界面显示及用户交互,并充分利用STM32硬件特性,提供一系列应用场…

    编程 2025-04-12
  • C#界面登场,探究其魅力所在

    C#界面作为.NET框架的一部分,为我们的开发提供了丰富的选择,并且面对的场景都是丰富多样的。下面我们将从多个方面对C#界面做出详细的阐述,帮助我们更好的理解和掌握这一技术。 一、…

    编程 2025-04-02
  • emxGUI: 创造你所想的图像界面!

    一、什么是emxGUI? emxGUI是一个基于轻量级GUI库的高度可定制的图像界面开发工具。它使用面向对象的方法组织代码,方便易懂,易扩展。提供更多控件组件和事件以及效果,可有效…

    编程 2025-02-24
  • Vue代码生成器可视化界面

    一、概述 Vue是一套构建用户界面的渐进式框架,拥有最佳的性能和体验。而在Vue的开发过程中,我们通常需要编写复杂的代码来实现特定的功能,这对于有经验的开发人员来说并不是问题,但是…

    编程 2025-02-17

发表回复

登录后才能评论