jsp登錄界面csdn(jsp登錄界面下拉列表)

本文目錄一覽:

用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如何實現像CSDN主頁右上角那種,登錄前顯示“你還未登錄”,“登陸”“註冊”登陸後顯示

放兩個div,一個裡面寫“你還未登錄”,另一個裡面寫“登錄|註冊”,至於鏈接自己加,然後div的display都設置成none,在登錄的servlet或者action中,登錄成功後,向request里放入islogin屬性,這樣寫request.setAttribute(“islogin”,”true”);

然後在頁面寫個js,接收request中的屬性islogin,js中這樣寫:

var islogin = “${requestScope.islogin}”;

然後判斷這個屬性,如果islogin==””,則沒有登錄,第一個div設置display:block,如果islogin==”true”就顯示第二個div

JSP編寫一個登陸界面

1、首先準備Dreamweaver8軟件,解壓安裝。如下圖所示:這件點擊安裝程序,然後輸入序列號就可以了。

2、在安裝軟件時候,我們可以看到是否關聯【jsp文件】。

3、安裝好了軟件以後,我們打開Dreamweaver8軟件。點擊菜單上的【文件】——【新建】。

4、彈出【新建文檔】——【動態頁】——【jsp】——【創建】。

5、點擊【拆分】,在【body】標籤下面輸入:%     out.println(“Hello World!”);     %。

6、然後按快捷鍵【ctrl+s】保存jsp文件。保存類型jps;。

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

原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/284980.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
小藍的頭像小藍
上一篇 2024-12-22 15:42
下一篇 2024-12-22 15:42

相關推薦

  • Python字符轉列表指南

    Python是一個極為流行的腳本語言,在數據處理、數據分析、人工智能等領域廣泛應用。在很多場景下需要將字符串轉換為列表,以便於操作和處理,本篇文章將從多個方面對Python字符轉列…

    編程 2025-04-29
  • Python中不同類型的列表

    Python是一種功能強大的編程語言,其內置數據結構之一為列表。列表可以容納任意數量的元素,並且可以存儲不同類型的數據。 一、列表的基本操作 Python的列表類型支持許多操作,如…

    編程 2025-04-29
  • Python為什麼輸出空列表

    空列表是Python編程中常見的數據類型,在某些情況下,會出現輸出空列表的情況。下面我們就從多個方面為大家詳細闡述為什麼Python會輸出空列表。 一、賦值錯誤 在Python中,…

    編程 2025-04-29
  • 如何使用Python將print輸出到界面?

    在Python中,print是最常用的調試技巧之一。在編寫代碼時,您可能需要在屏幕上輸出一些值、字符串或結果,以便您可以更好地理解並調試代碼。因此,在Python中將print輸出…

    編程 2025-04-29
  • Python定義兩個列表的多面探索

    Python是一種強大的編程語言,開放源代碼,易於學習和使用。通過Python語言,我們可以定義各種數據類型,如列表(list)。在Python中,列表(list)在處理數據方面起…

    編程 2025-04-29
  • Python編程實現列表元素逆序存放

    本文將從以下幾個方面對Python編程實現列表元素逆序存放做詳細闡述: 一、實現思路 一般來說,使用Python將列表元素逆序存放可以通過以下幾個步驟實現: 1. 定義一個列表 2…

    編程 2025-04-29
  • Python列表的讀寫操作

    本文將針對Python列表的讀取與寫入操作進行詳細的闡述,包括列表的基本操作、列表的增刪改查、列表切片、列表排序、列表反轉、列表拼接、列表複製等操作。 一、列表的基本操作 列表是P…

    編程 2025-04-29
  • Python字典列表去重

    這篇文章將介紹如何使用Python對字典列表進行去重操作,並且從多個方面進行詳細的闡述。 一、基本操作 首先我們需要了解Python字典列表去重的基本操作。Python中提供了一種…

    編程 2025-04-28
  • Python列表套列表用法介紹

    本文將圍繞Python中的列表套列表展開詳細講解。 一、基本用法 Python中的列表套列表是一種非常常見和實用的數據結構。常見的用法是在一個大列表中嵌套若干個小列表。可以使用以下…

    編程 2025-04-28
  • 如何在Python中判斷列表長度為中心

    在Python中,很多時候我們需要對列表進行操作,而有時候需要根據列表長度來進行一些特定的操作。本文將討論如何在Python中判斷列表長度為中心。 一、使用len()函數判斷列表長…

    編程 2025-04-28

發表回復

登錄後才能評論