當前位置:首頁 » 網頁前端 » javaweb注冊登錄代碼
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

javaweb注冊登錄代碼

發布時間: 2022-12-21 11:10:04

❶ java web網頁登錄功能原理(最好有代碼❳

想要實現一個簡單的登錄功能的話,可以使用Servlet+jsp來實現,jsp編寫登錄界面和登錄後的要出現信息界面和登錄失敗的信息界面,Servlet類用來對表單提交的用戶名和密碼進行判斷和處理。

具體代碼如下:
Servlet類:
public class DemoServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String loginname = request.getParameter("loginname");
String password = request.getParameter("password");
if(loginname.equals("a") && password.equals("a")){
request.setAttribute("msg", "登錄成功");
request.getRequestDispatcher("/loginsuccess.jsp").forward(request, response);
}else{
request.setAttribute("msg", "登錄失敗");
request.getRequestDispatcher("/loginsuccess.jsp").forward(request, response);
}
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}
jsp頁面:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Demo</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>
<body>
<form action="demoServlet" method="post">
<input type="text" name="loginname"/><br/>
<input type="password" name="password"/><br/>
<input type="submit" value="登錄"/>
</form>
</body>
</html>
登錄信息頁面:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="標簽庫地址"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'loginsuccess.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>
<body>
${msg }
</body>
</html>

需要介紹一下:登錄信息的這個頁面中的${msg }是使用jstl標簽,需要在jsp頁面中導入jstl標簽庫,使用這個標簽庫可以節省很多代碼量。

❷ 大神,跪求java web 一個用戶用戶注冊登錄,不用連接資料庫,不要連接資料庫!!

這個簡單,定義一個static Map<String,User>,每注冊一個就往Map中put一條數據,以登錄名為key,以用戶User類為value。
登錄的時候拿著登錄名去找Map,如果有匹配到就對比密碼是否正確,密碼輸入正確就表示可以登錄成功,密碼匹配錯誤就提示密碼錯誤;
如果拿著登錄名找Map沒有找到信息,說明此登錄名沒有注冊,就是提示注冊。

❸ 用java web編寫一個用戶注冊界面(只要寫出以下要求就行)

一步步更新:頁面
<form action="regist.servlet" method="post"><table width="99%" border="0" align="center" cellpadding="0" cellspacing="0" class="tableAdd borTop"> <tr> <th width="14%" height="30" nowrap>用戶名</th> <td class="pl5"> <INPUT id="sName" name="name" type="text" size="20"> </td> </tr> <tr> <th width="14%" height="30" nowrap>密碼</th> <td class="pl5"> <INPUT name="password" type="password" size="20"> </td> </tr> <tr> <th width="14%" height="30" nowrap>確認密碼</th> <td class="pl5"> <INPUT name="confrimPwd" type="password" size="20"> </td> </tr> <tr> <th width="14%" height="30" nowrap>性別</th> <td class="pl5"> 男<INPUT name="sex" type="radio" value="1" checked="checked" size="20"> 女<INPUT name="sex" type="radio" value="0" size="20"> </td> </tr> <tr> <th width="14%" height="30" nowrap>愛好</th> <td class="pl5"> <INPUT name="enjoy" type="checkbox" size="20" value="籃球">籃球 <INPUT name="enjoy" type="checkbox" size="20" value="足球">足球 </td> </tr> <tr> <th width="14%" height="30" nowrap>生日</th> <td class="pl5"> <INPUT name="brithday" type="text" size="20"> </td> </tr> <tr> <th width="14%" height="30" nowrap>備注</th> <td class="pl5"> <textarea rows="5" cols="200" name="remark"></textarea> </td> </tr> <tr> <th width="14%" height="30" nowrap> </th> <td class="pl5"> <input type="submit" value="提交"> <input type="reset" value="重置"> </td> </tr></table></form>

資料庫部分:
import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import com.mysql.jdbc.Connection;import com.mysql.jdbc.Statement;public class DataBaseUtil { public static Connection getConnection() throws ClassNotFoundException, SQLException { Class.forName("com.mysql.jdbc.Driver"); Connection conn = (Connection) DriverManager.getConnection("jdbc:mysql://192.168.100.113/datebase", "username", "password"); return conn; } public static Statement getPS() throws ClassNotFoundException, SQLException { Statement statement = (Statement) getConnection().createStatement(); return statement; } public static void close(Connection conn,Statement st,ResultSet rs) throws SQLException{ if(rs != null) { rs.close(); } if(st != null) { st.close(); } if(conn != null) { conn.close(); } }}

❹ 關於javaWeb單點登錄

你這樣入手,給你列出整個簡單流程,你自己思考一下:

1)下載,配置 Tomcat。
2)寫 JSP 與 Servlet ,調用 MySQL 或其他資料庫。

3)在 Tomcat 部署你的應用程序。
4)在瀏覽器運行你的應用程序。

一個簡單的測試系統,主要由兩個頁面組成就夠了:

1)登錄頁面。
2)登錄成功後,顯示的主頁面。

後台程序,只要寫一個就行了:

1)接收登錄的用戶名密碼,去查詢資料庫。

❺ 用java寫一個手機商城注冊界面代碼

這篇文章主要介紹了java通過JFrame做一個登錄系統的界面完整代碼示例,具有一定借鑒價值,需要的朋友可以參考下。
在java的JFrame內通過創建匿名對象的方式做登錄界面
package com.sxt;
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class LoginFrame extends JFrame{
JTextField txtname=new JTextField();
JPasswordField txtpass=new JPasswordField();
JButton bl=new JButton("登錄");
JButton bg=new JButton("關閉");
//構造無參構造器把主要的方法放在構造器里,然後在main方法裡面調
public LoginFrame(){
setBounds(25,25,250,250);
Container c = getContentPane();
c.setLayout(new GridLayout(4,2,10,10));
c.add(new JLabel("用戶名"));
c.add(txtname);
c.add(new JLabel("密碼"));
c.add(txtpass);
c.add(bl);
c.add(bg);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
//注意:此處是匿名內部類
bg.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
System.exit(0);
}
}
);
//注意:此處是匿名內部類
bl.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {

❻ 急急急!!!!在線等!!javaweb怎麼判斷管理員和普通用戶登錄,求代碼!!!

if(request.getParameter("userclass").equals("用戶"))
...
else if(request.getParameter("userclass").equals("管理員")
...
else
...

❼ java web 的一個登錄注冊案例,控制台出現At least one JAR was scanned for TLDs yet contained no TLDs

user是一個對象,重寫一下user的tostring方法

❽ javaweb的學生注冊登錄(學號,姓名,密碼),刪除,修改

如果不多的話就直接修改 要更新就 update table set id='19'+substring(id,1,4)+'00'+substring(id,5,3)