jsp登陆界面源代码

2024-12-15 15:37:44
推荐回答(5个)
回答1:

1、login.jsp文件

<%@ page language="java" contentType="text/html; charset=GB18030"

pageEncoding="GB18030"%>

<%@ page import="java.util.*" %>

登录页面

用户名:
密码:

type="reset" value="重置" style="background-color:red">

2、judge.jsp文件

<%@ page language="java" contentType="text/html; charset=GB18030"

pageEncoding="GB18030"%>

<%@ page import="java.util.*" %>

身份验证

<%

request.setCharacterEncoding("GB18030");

String name = request.getParameter("userName");

String password = request.getParameter("password");

if(name.equals("abc")&& password.equals("123")) {

3、afterLogin.jsp文件

%>

<%

}

else {

%>

<%

}

%>

<%@ page language="java" contentType="text/html; charset=GB18030"

pageEncoding="GB18030"%>

登录成功

<%

request.setCharacterEncoding("GB18030");

String name = request.getParameter("userName");

out.println("欢迎你:" + name);

%>

扩展资料:

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

验证用户密码

<%

String username=(String)request.getParameter("username");

String password=(String)request.getParameter("password");

if(username==null||"".equals(username))

{

out.print("");

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("");

response.setHeader("refresh", "0;url=user_login.jsp");

}

else if(passwordInDataBase.equals(password))

{

out.print("");

response.setHeader("refresh", "0;url=loginSucces.jsp");

}

else

{

out.print("");

response.setHeader("refresh", "0;url=user_login.jsp");

}

}

%>

3、loginSucces.jsp文件

<%@ page language="java" contentType="text/html; charset=utf-8"

pageEncoding="utf-8"%>

Insert title here


登录成功


4、user_login.jsp文件

<%@ page language="java" contentType="text/html; charset=utf-8"

pageEncoding="utf-8"%>

登录界面







Login


   

账号
密码


回答2:

login.jsp文件

<%@ page language="java" contentType="text/html; charset=GB18030"

pageEncoding="GB18030"%>

<%@ page import="java.util.*" %>

登录页面

用户名:
密码:

type="reset" value="重置" style="background-color:red">

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();

}

}

}

回答3:

<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<%@ page import="java.util.*" %>



登录页面













用户名:
密码:





<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<%@ page import="java.util.*" %>



身份验证


<%
request.setCharacterEncoding("GB18030");
String name = request.getParameter("userName");
String password = request.getParameter("password");
if(name.equals("abc")&& password.equals("123")) {

%>



<%
}
else {
%>

<%
}
%>



<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>



登录成功


<%
request.setCharacterEncoding("GB18030");
String name = request.getParameter("userName");
out.println("欢迎你:" + name);
%>



总共3个jsp文件,第一个是login.jsp,第2个是judge.jsp,第3个是afterLogin.jsp

回答4:

<%@
page
language="java"
contentType="text/html;
charset=GB18030"
pageEncoding="GB18030"%>
<%@
page
import="java.util.*"
%>
HTML
PUBLIC
"-//W3C//DTD
HTML
4.01
Transitional//EN">


登录页面


name="loginForm"
method="post"
action="judgeUser.jsp">











用户名:type="text"
name="userName"
id="userName">
密码:type="password"
name="password"
id="password">
type="submit"
value="登录"
style="background-color:pink">
type="reset"
value="重置"
style="background-color:red">




<%@
page
language="java"
contentType="text/html;
charset=GB18030"
pageEncoding="GB18030"%>
<%@
page
import="java.util.*"
%>
HTML
PUBLIC
"-//W3C//DTD
HTML
4.01
Transitional//EN">


身份验证


<%
request.setCharacterEncoding("GB18030");
String
name
=
request.getParameter("userName");
String
password
=
request.getParameter("password");
if(name.equals("abc")&&
password.equals("123"))
{
%>
page="afterLogin.jsp">
name="userName"
value="<%=name%>"/>

<%
}
else
{
%>
page="login.jsp"/>
<%
}
%>


<%@
page
language="java"
contentType="text/html;
charset=GB18030"
pageEncoding="GB18030"%>
HTML
PUBLIC
"-//W3C//DTD
HTML
4.01
Transitional//EN">


登录成功


<%
request.setCharacterEncoding("GB18030");
String
name
=
request.getParameter("userName");
out.println("欢迎你:"
+
name);
%>


总共3个jsp文件,第一个是login.jsp,第2个是judge.jsp,第3个是afterLogin.jsp

回答5:

用几个html标签组成就可以出来登录界面啊