jsp用戶登錄註冊界面代碼(jsp實現登錄註冊)

本文目錄一覽:

編寫用戶註冊於登錄的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

如何用eclipse寫登錄註冊頁面的代碼

java寫的用戶登錄實例,實際頁面展示使用的jsp,那麼下面是jsp的登錄頁面代碼:

1、login.jsp代碼

%

string name = request.getparameter(“username”);

string pwd = request.getparameter(“password”);

//out.println(name+pwd);

string sql =”select * from info where username='”+name+”‘ and password='”+pwd+”‘”;

//out.println(sql);

statement stm= null;

resultset rs =null;

try

{

stm = conn.createstatement();

rs = stm.executequery(sql);

if(rs.next())

{

session.setattribute(“username”,name);

response.sendredirect(“index.html”);

}

else

{

response.sendredirect(“index1.html”);

}

}

catch(sqlexception e)

{

e.printstacktrace();

}

%

!–登錄的表單–

form name=”form1″ method=”post” action=”login.jsp”

p

label for=”username”/label 用戶名

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

/p

p

label for=”passwrod”/label 密碼

input type=”text” name=”passwrod” id=”passwrod”

/p

p

input type=”submit” name=”button” id=”button” value=”提交”

/p

/form

2、用戶信息表,存放用戶名和密碼:

user_info 表

create table if not exists `test` (

`id` int(8) not null auto_increment,

`username` char(150) default null,

`password` varchar(32),

`times` int(4) not null,

primary key (`id`)

) engine=myisam default charset=utf8 auto_increment=1 ;

JSP編寫一個登陸界面

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

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

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

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

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

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

求大神寫一下jsp的簡單的註冊界面代碼。

1.需要一個jsp頁面:

//login.jsp核心代碼:

form action=”${pageContext.request.contextPath}/servlet/UserServlet” method=”post”

input type=”text” name=”loginname” /input type=”password” name=”password”/

input type=”submit” value=”登錄”/

/form

2.需要一個servlet來驗證登錄信息

//UserServlet 核心代碼

class UserServlet extends HttpServlet{

protected void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {

process(request, response);

}

protected void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {

process(request, response);

}

private void process(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {

PrintWriter pw = response.getWriter();

request.setCharacterEncoding(“UTF-8”);

response.setContentType(“text/html”);

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

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

//創建一個service來處理業務邏輯(包括查詢資料庫操作)

UserService service = new UserService();

boolean bool = service.validateUser(loginname,password);

if(!bool){

pw.println(“用戶名或密碼錯誤”);

}else{

pw.println(“登錄成功”);

}

}

3.需要一個service處理業務邏輯(包括查詢資料庫操作)

//UserService 核心代碼

public class UserService{

/**

*查詢資料庫驗證用戶是否存在,返回boolean

*/

public boolean validateUser(String loginname,String password){

boolean bool = false;

Connection conn = null;

PreparedStatement ps = null;

//這裡以mysql為例

try {

Class.forName(“com.mysql.jdbc.Driver”).newInstance();

conn = DriverManager.getConnection(“jdbc:mysql://localhost:3306/test”, “root”, “”);

String sql = “select login_name,pass_word from t_user where login_name=? and pass_word=?”;

ps = conn.prepareStatement(sql);

ps.setString(0, loginname);

ps.setString(1, password);

ResultSet rs = ps.executeQuery();

if(rs.next()){

bool = true;

}

} catch (Exception e) {

e.printStackTrace();

} finally{

try {

if(conn != null){

conn.close();

conn = null;

}

if(ps != null){

ps.close();

ps = null;

}

} catch (SQLException e) {

e.printStackTrace();

}

}

return bool;

}

}

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

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

相關推薦

  • Python周杰倫代碼用法介紹

    本文將從多個方面對Python周杰倫代碼進行詳細的闡述。 一、代碼介紹 from urllib.request import urlopen from bs4 import Bea…

    編程 2025-04-29
  • Python字元串寬度不限制怎麼打代碼

    本文將為大家詳細介紹Python字元串寬度不限制時如何打代碼的幾個方面。 一、保持代碼風格的統一 在Python字元串寬度不限制的情況下,我們可以寫出很長很長的一行代碼。但是,為了…

    編程 2025-04-29
  • Python基礎代碼用法介紹

    本文將從多個方面對Python基礎代碼進行解析和詳細闡述,力求讓讀者深刻理解Python基礎代碼。通過本文的學習,相信大家對Python的學習和應用會更加輕鬆和高效。 一、變數和數…

    編程 2025-04-29
  • Python滿天星代碼:讓編程變得更加簡單

    本文將從多個方面詳細闡述Python滿天星代碼,為大家介紹它的優點以及如何在編程中使用。無論是剛剛接觸編程還是資深程序員,都能從中獲得一定的收穫。 一、簡介 Python滿天星代碼…

    編程 2025-04-29
  • 倉庫管理系統代碼設計Python

    這篇文章將詳細探討如何設計一個基於Python的倉庫管理系統。 一、基本需求 在著手設計之前,我們首先需要確定倉庫管理系統的基本需求。 我們可以將需求分為以下幾個方面: 1、庫存管…

    編程 2025-04-29
  • 寫代碼新手教程

    本文將從語言選擇、學習方法、編碼規範以及常見問題解答等多個方面,為編程新手提供實用、簡明的教程。 一、語言選擇 作為編程新手,選擇一門編程語言是很關鍵的一步。以下是幾個有代表性的編…

    編程 2025-04-29
  • Python實現簡易心形代碼

    在這個文章中,我們將會介紹如何用Python語言編寫一個非常簡單的代碼來生成一個心形圖案。我們將會從安裝Python開始介紹,逐步深入了解如何實現這一任務。 一、安裝Python …

    編程 2025-04-29
  • 怎麼寫不影響Python運行的長段代碼

    在Python編程的過程中,我們不可避免地需要編寫一些長段代碼,包括函數、類、複雜的控制語句等等。在編寫這些代碼時,我們需要考慮代碼可讀性、易用性以及對Python運行性能的影響。…

    編程 2025-04-29
  • Python愛心代碼動態

    本文將從多個方面詳細闡述Python愛心代碼動態,包括實現基本原理、應用場景、代碼示例等。 一、實現基本原理 Python愛心代碼動態使用turtle模塊實現。在繪製一個心形的基礎…

    編程 2025-04-29
  • 北化教務管理系統介紹及開發代碼示例

    本文將從多個方面對北化教務管理系統進行介紹及開發代碼示例,幫助開發者更好地理解和應用該系統。 一、項目介紹 北化教務管理系統是一款針對高校學生和教職工的綜合信息管理系統。系統實現的…

    編程 2025-04-29

發表回復

登錄後才能評論