含jsp的網頁源碼,jsp網站開發詳解

本文目錄一覽:

網上下的jsp源碼要怎麼用

需要部署到伺服器中

找到菜單 window → Show View → Servers,打開Servers視圖標籤,部署的Tomcat 服務

在這個服務上右擊,選擇「Add Deployment」

在新打開的對話框中,有一個Project項,選擇要部署的項目

點擊「Finish」完成部署

這樣項目就部署到Tomcat裡面去了

運行JSP頁面顯示源碼

localhost:8080 tomcat的主頁打得開嗎?

打不開的話就是項目沒有配置到Tomcat,打得開的話新建一個運行再試試。

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

jsp 中網站的首頁源代碼

這是最簡單的一個例子,資料庫要你自己建,用的是ACCESS

%@ page contentType=”text/html; charset=gb2312″ language=”java” import=”java.sql.*” errorPage=”” %

html

head

meta http-equiv=”Content-Type” content=”text/html; charset=gb2312″

titleJSP連接Access資料庫/title

style type=”text/css”

!–

.style1 {

font-size: 20px;

font-weight: bold;

}

/style

/headbody

div align=”center” class=”style1″JSP連接Access資料庫/div

br

hr

p%

Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”); //載入驅動程序類別

Connection con = DriverManager.getConnection(“jdbc:odbc:jspdata”); //建立資料庫鏈接,jspdata為ODBC數據源名稱

//建立Statement對象

Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,

ResultSet.CONCUR_READ_ONLY);

ResultSet rs = stmt.executeQuery(“select * from lyb”); //建立ResultSet(結果集)對象,並執行SQL語句

%

/p

p align=”center”NUMB1數據表中記錄如下/p

table width=”640″ border=”1″ align=”center” bordercolor=”#7188e0″

tr bgcolor=”d1d1ff”

th width=”49″編號/th

th width=”90″姓名/th

th width=”126″E-mail/th

th width=”221″網站/th

th width=”80″QQ/th

/tr

%

while(rs.next())

{

%

tr bgcolor=”#f8f8f8″

th%= rs.getString(1) %/th

th%= rs.getString(2) %/th

th%= rs.getString(3) %/th

th bgcolor=”#f6f6f8″%= rs.getString(4) %/th

th%= rs.getString(5) %/th

/tr

%

}

rs.close();

stmt.close();

con.close();

%

/table

p align=”center”br

如果您能看到表格中的數據,說明連接資料庫成功!/p

/body

/html

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

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

相關推薦

  • 雲智直聘 源碼分析

    本文將會對雲智直聘的源碼進行分析,包括前端頁面和後端代碼,幫助讀者了解其架構、技術實現以及對一些常見的問題進行解決。通過本文的閱讀,讀者將會了解到雲智直聘的特點、優勢以及不足之處,…

    編程 2025-04-29
  • python爬取網頁並生成表格

    本文將從以下幾個方面詳細介紹如何使用Python爬取網頁數據並生成表格: 一、獲取網頁數據 獲取網頁數據的一般思路是通過HTTP請求獲取網頁內容,最常用的方式是使用Python庫r…

    編程 2025-04-28
  • 網頁防篡改的重要性和市場佔有率

    網頁防篡改對於保護網站安全和用戶利益至關重要,而市場上針對網頁防篡改的產品和服務也呈現出不斷增長的趨勢。 一、市場佔有率 據不完全統計,目前全球各類網頁防篡改產品和服務的市場規模已…

    編程 2025-04-28
  • Python網站源碼解析

    本文將從多個方面對Python網站源碼進行詳細解析,包括搭建網站、數據處理、安全性等內容。 一、搭建網站 Python是一種高級編程語言,適用於多種領域。它也可以用於搭建網站。最常…

    編程 2025-04-28
  • Python編程實戰:用Python做網頁與HTML

    Python語言是一種被廣泛應用的高級編程語言,也是一種非常適合於開發網頁和處理HTML的語言。在本文中,我們將從多個方面介紹如何用Python來編寫網頁和處理HTML。 一、Py…

    編程 2025-04-28
  • Python爬取網頁信息

    本文將從多個方面對Python爬取網頁信息做詳細的闡述。 一、爬蟲介紹 爬蟲是一種自動化程序,可以模擬人對網頁進行訪問獲取信息的行為。通過編寫代碼,我們可以指定要獲取的信息,將其從…

    編程 2025-04-28
  • 源碼是什麼

    源碼是一段計算機程序的原始代碼,它是程序員所編寫的可讀性高、理解性強的文本。在計算機中,源碼是指編寫的程序代碼,這些代碼按照一定規則排列,被計算機識別並執行。 一、源碼的組成 源碼…

    編程 2025-04-27
  • Go源碼閱讀

    Go語言是Google推出的一門靜態類型、編譯型、並髮型、語法簡單的編程語言。它因具有簡潔高效,內置GC等優秀特性,被越來越多的開發者所鍾愛。在這篇文章中,我們將介紹如何從多個方面…

    編程 2025-04-27
  • 使用Python轉髮網頁內容

    Python是一種廣泛使用的編程語言,它在網路爬蟲、數據分析、人工智慧等領域都有廣泛的應用。其中,使用Python轉髮網頁內容也是一個常見的應用場景。在本文中,我們將從多個方面詳細…

    編程 2025-04-27
  • Python批量爬取網頁內容

    Python是當前最流行的編程語言之一,其在數據處理、自動化任務、網路爬蟲等場景下都有廣泛應用。本文將介紹如何使用Python批量爬取網頁內容,方便獲取大量有用的數據。 一、安裝所…

    編程 2025-04-27

發表回復

登錄後才能評論