導航:首頁 > 編程語言 > java網頁登陸

java網頁登陸

發布時間:2023-07-16 09:10:05

『壹』 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實現簡單的用戶登錄需要哪些技術

簡單的話,就是jsp頁面有個用戶信息表單,點擊提交就跑到後台servlet
然後後台就校驗用戶身份信息,信息可以從資料庫拿,用jdbc連接資料庫最簡單了
完了之後就用response響應請求,或者是發request請求新的登錄成功頁面jsp

『叄』 java 爬蟲登陸網頁

最簡單的辦法就是 在論壇頁面審查元素,找到登錄按鈕,找到他的action,把它傳到你的程序裡面就好了,比如我現在回答你的問題,下面的提交回答按鈕也會有一個action

『肆』 如何用java實現登陸網站--不需打開瀏覽器

public static void loginBai() {
URL url = null;
HttpURLConnection httpurlconnection = null;
try {
url = new URL("http://www..com/");
httpurlconnection = (HttpURLConnection) url.openConnection();
httpurlconnection.setRequestProperty("User-Agent",
"Internet Explorer");
httpurlconnection.setRequestProperty("Host", "www..com");
httpurlconnection.connect();

String cookie0 = httpurlconnection.getHeaderField("Set-Cookie");

System.out.println(cookie0);//列印出cookie
httpurlconnection.disconnect();
// String cookie0 =
// "BAIDUID=:FG=1;BDSTAT=;
// BDUSE=deleted";
url = new URL("http://passport..com/?login");
String strPost = "username=xxxxxx&password=yyyyyyy&mem_pass=on";
httpurlconnection = (HttpURLConnection) url.openConnection();
httpurlconnection.setFollowRedirects(true);
httpurlconnection.setInstanceFollowRedirects(true);
httpurlconnection.setDoOutput(true); // 需要向伺服器寫數據
httpurlconnection.setDoInput(true); //
httpurlconnection.setUseCaches(false); // 獲得伺服器最新的信息
httpurlconnection.setAllowUserInteraction(false);
httpurlconnection.setRequestMethod("POST");
httpurlconnection
.addRequestProperty(
"Accept",
"image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/msword, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/x-silverlight, */*");
httpurlconnection
.setRequestProperty("Referer",
"http://passport..com/?login&tpl=mn&u=http%3A//www..com/");
httpurlconnection.setRequestProperty("Accept-Language", "zh-cn");
httpurlconnection.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded");
httpurlconnection.setRequestProperty("Accept-Encoding",
"gzip, deflate");
httpurlconnection
.setRequestProperty(
"User-Agent",
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Foxy/1; .NET CLR 2.0.50727;MEGAUPLOAD 1.0)");
httpurlconnection.setRequestProperty("Host", "passport..com");
httpurlconnection.setRequestProperty("Content-Length", strPost
.length()
+ "");
httpurlconnection.setRequestProperty("Connection", "Keep-Alive");
httpurlconnection.setRequestProperty("Cache-Control", "no-cache");
httpurlconnection.setRequestProperty("Cookie", cookie0);
httpurlconnection.getOutputStream().write(strPost.getBytes());
httpurlconnection.getOutputStream().flush();
httpurlconnection.getOutputStream().close();
httpurlconnection.connect();
int code = httpurlconnection.getResponseCode();
System.out.println("code " + code);
String cookie1 = httpurlconnection.getHeaderField("Set-Cookie");
System.out.print(cookie0 + "; " + cookie1);
httpurlconnection.disconnect();
url = new URL("http://www..com/");
httpurlconnection = (HttpURLConnection) url.openConnection();
httpurlconnection.setRequestProperty("User-Agent",
"Internet Explorer");
httpurlconnection.setRequestProperty("Host", "www..com");
httpurlconnection.setRequestProperty("Cookie", cookie0 + "; "
+ cookie1);
httpurlconnection.connect();
InputStream urlStream = httpurlconnection.getInputStream();
BufferedInputStream buff = new BufferedInputStream(urlStream);
Reader r = new InputStreamReader(buff, "gbk");
BufferedReader br = new BufferedReader(r);
StringBuffer strHtml = new StringBuffer("");
String strLine = null;
while ((strLine = br.readLine()) != null) {
strHtml.append(strLine + "\r\n");
}
System.out.print(strHtml.toString());
} catch (Exception e) {
e.printStackTrace();
} finally {
if (httpurlconnection != null)
httpurlconnection.disconnect();
}
}

呵呵,改了下程序中錯誤的地方。學習了,原來這樣也可以。
以前只知道可以這樣做,還從來沒有花過心思去做過。
閱讀了些代碼,真是獲益匪淺啊。

程序可以運行了,用戶名和密碼改為你的帳戶就可以直接運行了。可以使用,但不能一直使用啊,如果用多了網路給你個驗證碼,就是神仙也不行了。

『伍』 如何用JAVA編寫一個簡單用戶登陸界面

什麼都不說了 直接給你代碼吧x0dx0apackage com.moliying.ui;x0dx0aimport java.awt.BorderLayout;x0dx0aimport java.awt.Container;x0dx0aimport java.awt.FlowLayout;x0dx0aimport java.awt.List;x0dx0aimport java.awt.event.ActionEvent;x0dx0aimport java.awt.event.ActionListener;x0dx0aimport java.io.BufferedWriter;x0dx0aimport java.io.FileOutputStream;x0dx0aimport java.io.OutputStreamWriter;x0dx0aimport java.util.ArrayList;x0dx0aimport java.util.Arrays;x0dx0aimport javax.swing.JButton;x0dx0aimport javax.swing.JFrame;x0dx0aimport javax.swing.JLabel;x0dx0aimport javax.swing.JPanel;x0dx0aimport javax.swing.JPasswordField;x0dx0aimport javax.swing.JTextField;x0dx0apublic class Login {x0dx0aprivate JFrame frame = new JFrame("登錄");x0dx0aprivate Container c = frame.getContentPane();x0dx0aprivate JTextField username = new JTextField();x0dx0aprivate JPasswordField password = new JPasswordField();x0dx0aprivate JButton ok = new JButton("確定");x0dx0aprivate JButton cancel = new JButton("取消");x0dx0apublic Login() {x0dx0aframe.setSize(300, 200);x0dx0aframe.setBounds(450, 300, 300, 200);x0dx0ac.setLayout(new BorderLayout());x0dx0ainitFrame();x0dx0aframe.setVisible(true);x0dx0a}x0dx0aprivate void initFrame() {x0dx0a// 頂部x0dx0aJPanel titlePanel = new JPanel();x0dx0atitlePanel.setLayout(new FlowLayout());x0dx0atitlePanel.add(new JLabel("系統管理員登錄"));x0dx0ac.add(titlePanel, "North");x0dx0a// 中部表單x0dx0aJPanel fieldPanel = new JPanel();x0dx0afieldPanel.setLayout(null);x0dx0aJLabel a1 = new JLabel("用戶名:");x0dx0aa1.setBounds(50, 20, 50, 20);x0dx0aJLabel a2 = new JLabel("密 碼:");x0dx0aa2.setBounds(50, 60, 50, 20);x0dx0afieldPanel.add(a1);x0dx0afieldPanel.add(a2);x0dx0ausername.setBounds(110, 20, 120, 20);x0dx0apassword.setBounds(110, 60, 120, 20);x0dx0afieldPanel.add(username);x0dx0afieldPanel.add(password);x0dx0ac.add(fieldPanel, "Center");x0dx0a// 底部按鈕x0dx0aJPanel buttonPanel = new JPanel();x0dx0abuttonPanel.setLayout(new FlowLayout());x0dx0abuttonPanel.add(ok);x0dx0abuttonPanel.add(cancel);x0dx0ac.add(buttonPanel, "South");x0dx0ax0dx0aok.addActionListener(new ActionListener() {x0dx0ax0dx0a@Overridex0dx0apublic void actionPerformed(ActionEvent e) {x0dx0aSystem.out.println(username.getText().toString());x0dx0a}x0dx0a});x0dx0ax0dx0acancel.addActionListener(new ActionListener() {x0dx0ax0dx0a@Overridex0dx0apublic void actionPerformed(ActionEvent e) {x0dx0aframe.setVisible(false);x0dx0a}x0dx0a});x0dx0a}x0dx0apublic static void main(String[] args) {x0dx0a//new Login();x0dx0ax0dx0aString ss = "abbabbbaabbbccba";x0dx0ax0dx0aSystem.out.println(ss.split("b").length);x0dx0ax0dx0a}x0dx0a}

閱讀全文

與java網頁登陸相關的資料

熱點內容
拆傢具用什麼app 瀏覽:43
單片機國內外 瀏覽:651
函數的運演算法則題目 瀏覽:719
有免費編譯軟體嗎 瀏覽:918
java互聯網公司 瀏覽:70
對弈下象棋的app哪裡好 瀏覽:707
有什麼食譜app推薦 瀏覽:471
python實現動態口令 瀏覽:825
我的世界電腦伺服器地址怎麼添加 瀏覽:850
傳奇地圖怎麼加密到pak 瀏覽:977
linux刪除mysql用戶 瀏覽:755
圖案設計pdf 瀏覽:584
pdf編輯器在線 瀏覽:471
華為雲雲耀伺服器如何關機 瀏覽:994
數字加密的歷史 瀏覽:613
宏傑文件夾打不開 瀏覽:819
施工日記app哪個好 瀏覽:566
什麼是壓縮機的排氣量 瀏覽:538
在哪個app可以預約一科考試 瀏覽:634
易語言vmp加殼源碼 瀏覽:513