包含jsp生鮮系統界面源代碼的詞條

本文目錄一覽:

求大神寫一下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;

}

}

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編寫一個登陸界面

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

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

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

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

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

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

jsp文件用IE打開出現的是源代碼?

JSP文件打開是需要部署到服務器端的,如tomcat

直接放到Webapps目錄下就可以了,步驟如下:

Tomcat的Webapps目錄是Tomcat默認的應用目錄,務器啟動時,會加載所有這個目錄 下的應用。

也可以將JSP程序打包成一個war包放在目錄下,服務器會自動解開這個war包,並在這個目錄下生成一個同名的文件夾。

一個war包就是有特 性格式的jar包,它是將一個Web程序的所有內容進行壓縮得到。

在程序執行中打包:

try{

string strjavahome = system.getproperty(“java.home”);

strjavahome = strjavahome.substring(0,strjavahome.lastindexof(\\))+”\\bin\\”;

runtime.getruntime().exec(“cmd /c start “+strjavahome+”jar cvf hello.war c:\\tomcat5.0\\webapps\\root\\*”);

}

catch(exception e){system.out.println(e);}

webapps這個默認的應用目錄也是可以改變。

打開Tomcat的conf目錄下的server.xml文件,找到下面內容即可:

Host name=”localhost” debug=”0″ appBase=”webapps” unpackWARs=”true” autoDeloy=”true” xmlValidation=”falase” xmlNamespaceAware=”false”

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

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
E3OQA的頭像E3OQA
上一篇 2024-10-03 23:25
下一篇 2024-10-03 23:25

相關推薦

  • g3log源代碼學習

    g3log是一個高性能C++日誌庫,其代碼十分精簡和可讀性強,本文將從3個方面詳細介紹g3log源代碼學習。 一、g3log源代碼整體架構 g3log的整體架構十分清晰,其中有3個…

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

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

    編程 2025-04-29
  • 數字孿生源代碼的介紹

    數字孿生源代碼是一種用於模擬現實世界的技術。它將現實世界的實體或場景進行數字化,使得我們可以通過計算機程序對其進行模擬,以便進行分析和預測。數字孿生源代碼包含了許多組件和算法,下面…

    編程 2025-04-28
  • Python 如何進入編程界面?

    Python 是一種廣泛應用於 Web、遊戲、網絡爬蟲等領域的高級編程語言。Python 雖然易學易用,但還是需要一些工具和步驟來實際編寫運行程序。 一、命令行模式 在命令行模式下…

    編程 2025-04-27
  • Python GUI界面詳解

    Graphical User Interface (GUI) 即圖形用戶界面,為用戶提供了更加方便直觀的操作形式,已經是現代軟件的標配。作為一名全能編程開發工程師,掌握Python…

    編程 2025-04-23
  • ViewRootImpl:Android應用界面的核心類

    一、ViewRootImpl的作用 ViewRootImpl是Android應用界面的核心類,它的作用是連接View和WindowManager,負責處理輸入事件的分發、View的…

    編程 2025-04-12
  • 使用lvglstm32打造高性能嵌入式UI界面

    一、簡介 lvglstm32是基於lvgl嵌入式UI庫和STM32系列單片機的一款開源項目。它能夠實現高性能的圖形界面顯示及用戶交互,並充分利用STM32硬件特性,提供一系列應用場…

    編程 2025-04-12
  • C#界面登場,探究其魅力所在

    C#界面作為.NET框架的一部分,為我們的開發提供了豐富的選擇,並且面對的場景都是豐富多樣的。下面我們將從多個方面對C#界面做出詳細的闡述,幫助我們更好的理解和掌握這一技術。 一、…

    編程 2025-04-02
  • 如何查看exe文件的源代碼

    一、使用反彙編工具檢查 反彙編工具是一種將機器語言轉發成彙編語言的軟件工具,也可以將目標文件(例如exe)文件轉化為可讀性較好的彙編代碼。 下面是一個使用IDA反彙編工具對exe文…

    編程 2025-02-25
  • emxGUI: 創造你所想的圖像界面!

    一、什麼是emxGUI? emxGUI是一個基於輕量級GUI庫的高度可定製的圖像界面開發工具。它使用面向對象的方法組織代碼,方便易懂,易擴展。提供更多控件組件和事件以及效果,可有效…

    編程 2025-02-24

發表回復

登錄後才能評論