1、loginjsp文件
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<%@ page import="javautil" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 401 Transitional//EN">
<html>
<head>
<title>登录页面</title>
</head>
<body>
<form name="loginForm" method="post" action="judgeUserjsp">
<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、judgejsp文件
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<%@ page import="javautil" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 401 Transitional//EN">
<html>
<head>
<title>身份验证</title>
</head>
<body>
<%
requestsetCharacterEncoding("GB18030");
String name = requestgetParameter("userName");
String password = requestgetParameter("password");
if(nameequals("abc")&& passwordequals("123")) {
3、afterLoginjsp文件
%>
<jsp:forward page="afterLoginjsp">
<jsp:param name="userName" value="<%=name%>"/>
</jsp:forward>
<%
}
else {
%>
<jsp:forward page="loginjsp"/>
<%
}
%>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 401 Transitional//EN">
<html>
<head>
<title>登录成功</title>
</head>
<body>
<%
requestsetCharacterEncoding("GB18030");
String name = requestgetParameter("userName");
outprintln("欢迎你:" + name);
%>
</body>
</html>
扩展资料:
java web登录界面源代码:
1、Data_uiljava文件
import javasql;
public class Data_uil
{
public Connection getConnection()
{
try{
ClassforName("commicrosoftsqlserverjdbcSQLServerDriver");
}catch(ClassNotFoundException e)
{
eprintStackTrace();
}
String user="";
String password="";
String url="jdbc:sqlserver://127001:1433;DatabaseName=";
Connection con=null;
try{
con=DriverManagergetConnection(url,user,password);
}catch(SQLException e)
{
eprintStackTrace();
}
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=connectionprepareStatement(sql);
preparedStatementsetString(1,username);
result=preparedStatementexecuteQuery();//可执行的 查询
if(resultnext())
password=resultgetString("password");
}catch(SQLException e){
eprintStackTrace();
}finally
{
close(preparedStatement);
close(result);
close(connection);
}
Systemoutprintln("找到的数据库密码为:"+password);
return password;
}
public void close (Connection con)
{
try{
if(con!=null)
{
conclose();
}
}catch(SQLException e)
{
eprintStackTrace();
}
}
public void close (PreparedStatement preparedStatement)
{
try{
if(preparedStatement!=null)
{
preparedStatementclose();
}
}catch(SQLException e)
{
eprintStackTrace();
}
}
public void close(ResultSet resultSet)
{
try{
if(resultSet!=null)
{
resultSetclose();
}
}catch(SQLException e)
{
eprintStackTrace();
}
}
}
2、login_checkjsp:文件
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 401 Transitional//EN" ">
<html>
<head>
<meta >
<title>验证用户密码</title>
</head>
<body>
<jsp:useBean id="util" class="utilData_uil" scope="page" />
<%
String username=(String)requestgetParameter("username");
String password=(String)requestgetParameter("password");
if(username==null||""equals(username))
{
outprint("<script language='javaScript'> alert('用户名不能为空');</script>");
responsesetHeader("refresh", "0;url=user_loginjsp");
}
else
{
Systemoutprintln("输入的用户名:"+username);
String passwordInDataBase=utilselectPassword(username);
Systemoutprintln("密码:"+passwordInDataBase);
if(passwordInDataBase==null||""equals(passwordInDataBase))
{
outprint("<script language='javaScript'> alert('用户名不存在');</script>");
responsesetHeader("refresh", "0;url=user_loginjsp");
}
else if(passwordInDataBaseequals(password))
{
outprint("<script language='javaScript'> alert('登录成功');</script>");
responsesetHeader("refresh", "0;url=loginSuccesjsp");
}
else
{
outprint("<script language='javaScript'> alert('密码错误');</script>");
responsesetHeader("refresh", "0;url=user_loginjsp");
}
}
%>
</body>
</html>
3、loginSuccesjsp文件
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 401 Transitional//EN" ">
<html>
<head>
<meta >
<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_loginjsp文件
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 401 Transitional//EN" ">
<html>
<head>
<meta >
<title>登录界面</title>
</head>
<body background="C:\Users\win8\workspace\Login\image\9dcbdc339e72a5663b5c289fb5573c13_10jpg" >
<center>
<br><br><br><br><br><br>
<h1 style="color:yellow">Login</h1>
<br>
<form name="loginForm" action="login_checkjsp" 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(Java Server Pages)是由Sun Microsystems公司倡导、许多公司参与一起建立的一种动态网页,打开方式如下:
1、我们先打开IE浏览器,如下图所示:
2、再找到并打开JSP源文件所在的文件夹,如下图所示:
3、鼠标左键选中并按住jsp文件不放,拖动到浏览器窗口并释放鼠标左键,如下图所示:
4、浏览器中显示出了这个jsp程序的执行结果,如下图所示:
以上就是关于jsp登陆界面源代码全部的内容,包括:jsp登陆界面源代码、jsp是什么文件格式,怎么打开、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)