最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

Java web:重名驗證load-on-startup servlet生命周期,學(xué)習(xí)筆記和代碼例子【詩書畫唱】

2020-09-18 00:49 作者:詩書畫唱  | 我要投稿


寫完這篇專欄的時間(給個三連吧):


自己想出來的巧妙的重名驗證方法關(guān)鍵:


1、創(chuàng)建一個servlet,運行它能夠打印出訪問這個servlet的次數(shù)

package com.jy;


import java.io.IOException;

import javax.servlet.ServletException;

import javax.servlet.annotation.WebServlet;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;


@WebServlet("/ms")

public class FangWenCount extends HttpServlet {

private static final long serialVersionUID = 1L;

private Integer count = 0;

? ??

? ? public FangWenCount() {

? ? ? ? super();

? ? ? ? // TODO Auto-generated constructor stub

? ? }

??

protected void doGet(HttpServletRequest request,

HttpServletResponse response) throws?

ServletException, IOException {

// TODO Auto-generated method stub

this.doPost(request, response);

}


protected void doPost(HttpServletRequest request,

HttpServletResponse response)?

throws ServletException, IOException {

// TODO Auto-generated method stub

count ++;

System.out.println("訪問這個servlet的次數(shù):"+count+"次");

}


}




2、創(chuàng)建兩個load-on-startup servlet,要求啟動項目后,后面寫的servlet先運行。


package com.SSHC;


import java.io.IOException;

import javax.servlet.ServletException;

import javax.servlet.annotation.WebServlet;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;


/**

?* Servlet implementation class LosServlet

?*/

public class loadOnStartup1 extends HttpServlet {

private static final long serialVersionUID = 1L;

? ? ? ?

? ? /**

? ? ?* @see HttpServlet#HttpServlet()

? ? ?*/

? ? public loadOnStartup1() {

? ? ? ? super();

? ? ? ? // TODO Auto-generated constructor stub

? ? }


@Override

public void init() throws ServletException {

// TODO Auto-generated method stub

System.out.println("隨著項目啟動運行的Loadonstartup servlet"

+ ":loadOnStartup1");

}


}


package com.SSHC;


import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;


public class loadOnStartup2 extends HttpServlet {


@Override

public void init() throws ServletException {

// TODO Auto-generated method stub

System.out.println("另外的一個Loadonstartup servlet:loadOnStartup2");

}


}


<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"?

xmlns="http://java.sun.com/xml/ns/javaee"?

xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http:

//java.sun.com/xml/ns/javaee/web-app_3_0.xsd"?

id="WebApp_ID" version="3.0">

? <display-name>JavaWebJSP</display-name>

??

<servlet>


<servlet-name>firstServlet-name</servlet-name>


<servlet-class>com.SSHC.loadOnStartup1</servlet-class>


<load-on-startup>2</load-on-startup>


</servlet>



<servlet>


<servlet-name>secondServlet-name</servlet-name>


<servlet-class>com.SSHC.loadOnStartup2</servlet-class>


<load-on-startup>1</load-on-startup>


</servlet>

? <welcome-file-list>

? ? <welcome-file>index.html</welcome-file>

? ? <welcome-file>index.htm</welcome-file>

? ? <welcome-file>index.jsp</welcome-file>

? ? <welcome-file>default.html</welcome-file>

? ? <welcome-file>default.htm</welcome-file>

? ? <welcome-file>default.jsp</welcome-file>

? </welcome-file-list>

</web-app>

在項目處鼠標(biāo)右鍵,點"Run as"等:



3、創(chuàng)建一個servlet,第一次運行時在后臺打印"您是第1個訪問本應(yīng)用的客戶"

package com.SSHC;


import java.io.IOException;

import javax.servlet.ServletException;

import javax.servlet.annotation.WebServlet;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;


@WebServlet("/CountPerson")

public class CountPerson extends HttpServlet {

private static final long serialVersionUID = 1L;

private Integer count = 0;

? ??

? ? public CountPerson() {

? ? ? ? super();

? ? ? ? // TODO Auto-generated constructor stub

? ? }

??

protected void doGet(HttpServletRequest request,

HttpServletResponse response) throws?

ServletException, IOException {

// TODO Auto-generated method stub

this.doPost(request, response);

}


protected void doPost(HttpServletRequest request,

HttpServletResponse response)?

throws ServletException, IOException {

// TODO Auto-generated method stub

count ++;

System.out.println("您是第"+count+"個訪問本應(yīng)用的客戶");

}


}



4、在WEB-INF目錄下創(chuàng)建一個reg.jsp頁面,創(chuàng)建一個servlet,當(dāng)運行這個servlet時跳轉(zhuǎn)到reg.jsp頁面。(WEB-INF目錄下的jsp頁面只有通過轉(zhuǎn)發(fā)的方式才可以訪問到,

不能通過http://localhost:8080/J190801/WEB-INF/my.jsp的方式訪問

package com.SSHC;


import java.io.IOException;

import javax.servlet.ServletException;

import javax.servlet.annotation.WebServlet;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;


/**

?* Servlet implementation class tiaoZhuanWEB

?*/

@WebServlet("/tiaoZhuanWEB")

public class tiaoZhuanWEB extends HttpServlet {

private static final long serialVersionUID = 1L;

? ? ? ?

? ? /**

? ? ?* @see HttpServlet#HttpServlet()

? ? ?*/

? ? public tiaoZhuanWEB() {

? ? ? ? super();

? ? ? ? // TODO Auto-generated constructor stub

? ? }


/**

* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)

*/

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

// TODO Auto-generated method stub

this.doPost(request, response);

}


/**

* @see HttpServlet#doPost(HttpServletRequest request,?

* HttpServletResponse response)

*/

protected void doPost(HttpServletRequest request,

HttpServletResponse response)

throws ServletException, IOException {


// TODO Auto-generated method stub

request.getRequestDispatcher("WEB-INF/reg.jsp")

.forward(request, response);

?

}


}



<%@ page language="java" contentType="text/html; charset=utf-8"

? ? pageEncoding="utf-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<title>Insert title here</title>

</head>

<body>

用轉(zhuǎn)發(fā)的方式成功跳轉(zhuǎn)到WEB-INF目錄下的reg.jsp界面!


<%System.out.println("用轉(zhuǎn)發(fā)的方式成功跳轉(zhuǎn)到WEB-INF目錄下的reg.jsp界面!"); %>

</body>

</html>



5、設(shè)計一個servlet,運行它能夠跳轉(zhuǎn)到b站


package com.SSHC;


import java.io.IOException;

import javax.servlet.ServletException;

import javax.servlet.annotation.WebServlet;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;


/**

?* Servlet implementation class BaiduServlet

?*/

@WebServlet("/bs")

public class BilibiliTiaoZhuanServlet extends HttpServlet {

private static final long serialVersionUID = 1L;

? ? ? ?

? ? /**

? ? ?* @see HttpServlet#HttpServlet()

? ? ?*/

? ? public BilibiliTiaoZhuanServlet() {

? ? ? ? super();

? ? ? ? // TODO Auto-generated constructor stub

? ? }


/**

* @see HttpServlet#doGet(HttpServletRequest

*? request, HttpServletResponse response)

*/

protected void doGet(HttpServletRequest request,?

HttpServletResponse response)?

throws ServletException, IOException {

// TODO Auto-generated method stub

this.doPost(request, response);

}


/**

* @see HttpServlet#doPost(HttpServletRequest?

* request, HttpServletResponse response)

*/

protected void doPost(HttpServletRequest request,

HttpServletResponse response)?

throws ServletException, IOException {

// TODO Auto-generated method stub

//跳轉(zhuǎn)百度頁面

response.sendRedirect("http://www.bilibili.com";);

}


}


<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<%

? ? String path = request.getContextPath();

? ? String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

? ? <head>

? ? ? ? <base hreff="<%=basePath%>">

? ? ? ? <title></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">

? ? ? ? <script type="text/javascript">

? ? ? ? ? ? function naviTo(){

? ? ? ? ? ?

? ? ? ? ? ? window.location.hreff = 'bs';

? ? ? ? ? ? }

? ? ? ? </script>

? ? </head>

? ? <body>

? ? ? ? <input type="button" value="bilibil" onclick="naviTo();"/>

? ? ? ? <a hreff="javascript:naviTo();">點擊后按鈕或超鏈接跳轉(zhuǎn)到bilibili</a>

? ? </body>

</html>




6、實現(xiàn)重名驗證的業(yè)務(wù)。



package com.SSHC;


import java.io.IOException;

import java.util.ArrayList;

import java.util.List;


import javax.servlet.ServletException;

import javax.servlet.annotation.WebServlet;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;


import com.SSHC.DAO.UserDao;

import com.SSHC.bean.User;


/**

?* Servlet implementation class RegServlet

?*/

@WebServlet("/rs")

public class RegServlet extends HttpServlet {

private static final long serialVersionUID = 1L;

? ? ? ?

? ? /**

? ? ?* @see HttpServlet#HttpServlet()

? ? ?*/

? ? public RegServlet() {

? ? ? ? super();

? ? ? ? // TODO Auto-generated constructor stub

? ? }


/**

* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)

*/

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

// TODO Auto-generated method stub

this.doPost(request, response);

}


/**

* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)

*/

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


//中文亂碼處理:

? ? request.setCharacterEncoding("utf-8");

? ? //1、獲取用戶輸入的賬號和密碼:

? ? String act = request.getParameter("act");

? ? String pwd = request.getParameter("pwd");


? ? //2、查詢數(shù)據(jù)庫:

? ? UserDao userDao = new UserDao();



String msg = "";


int num=1;

List<User> list = userDao.selectAll();


for(User U : list) {





String act1= U.getAct();


//? System.out.println(act1);

? if(act.equals(act1)) {

? num=num*0;

} else {

? num=num*2;

}?

??


} //有時用System.out.println(html)等來測試,找BUG等;


if(num==0) {

msg = "該賬號已被使用";

request.setAttribute("msg", msg);

request.getRequestDispatcher("dupName.jsp")

? ? .forward(request, response);

} else {

msg = "該賬號可以注冊";

request.setAttribute("msg", msg);

request.getRequestDispatcher("success.jsp")

? ? .forward(request, response);

}


}


}



package com.SSHC.bean;


import java.util.Date;


//bean的類名于表的名字一致,而且首字母必須大寫

public class User {

? ? //bean類中的屬性名應(yīng)該和表中的列名一致

private Integer id;

private String act;

private String pwd;

private String birth;

private String sex;

private String hobbys;

public Integer getId() {

return id;

}

public void setId(Integer id) {

this.id = id;

}

public String getAct() {

return act;

}

public void setAct(String act) {

this.act = act;

}

public String getPwd() {

return pwd;

}

public void setPwd(String pwd) {

this.pwd = pwd;

}

public String getBirth() {

return birth;

}

public void setBirth(String birth) {

this.birth = birth;

}

public String getSex() {

return sex;

}

public void setSex(String sex) {

this.sex = sex;

}

public String getHobbys() {

return hobbys;

}

public void setHobbys(String hobbys) {

this.hobbys = hobbys;

}


}

package com.SSHC.DAO;




import java.sql.Connection;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.util.ArrayList;

import java.util.List;






import com.SSHC.Utils.DBUtils;

import com.SSHC.bean.User;



//DAO(Data Access Object)是一個數(shù)據(jù)訪問接口,


//數(shù)據(jù)訪問:顧名思義就是與數(shù)據(jù)庫打交道。


//夾在業(yè)務(wù)邏輯與數(shù)據(jù)庫資源中間。


///DAO就是實現(xiàn)增刪改查的一個類


public class UserDao {


?//用XXXDao(XXX為表名比如Eduinfo),Eduinfo:教育信息。


///XXXDAO可查詢eduinfo表中的所有的數(shù)據(jù)。


//List用上泛型:


public List<User>selectAll(){


String sql = "select * from User";


Connection conn = null;


PreparedStatement pstm = null;


ResultSet rs = null;


List<User>list = new ArrayList<User>();


try {


// 下面用上DBUtils(當(dāng)然命名為Dbutil,也可以


// 自己知道是數(shù)據(jù)庫常用工具就可以了:


conn = DBUtils.getConn();


pstm = conn.prepareStatement(sql);


rs = pstm.executeQuery();


while(rs.next()) {


Integer id = rs.getInt("id");


String ename = rs.getString("act");


//進(jìn)行打包:


User edu = new User();


edu.setId(id);


edu.setAct(ename);


//繼續(xù)打包:


list.add(edu);


}


} catch (SQLException e) {


// TODO Auto-generated catch block


e.printStackTrace();


}


return list;


}




}

package com.SSHC.Utils;


import java.io.IOException;

import java.io.InputStream;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.util.Properties;


public class DBUtils {

private static String driverName;

? ? private static String url;

? ? private static String user;

? ? private static String pwd;

? ??

? ? static {

? ? //讀取properties文件

? ? Properties prop = new Properties();

? ? //將db.properties文件讀取到內(nèi)存中去

? ? InputStream is = DBUtils.class.getClassLoader()

? ? .getResourceAsStream("db.properties");

? ? //加載內(nèi)容

? ? try {

prop.load(is);

//讀取內(nèi)容

driverName = prop.getProperty("dn");

//System.out.println(driverName);

url = prop.getProperty("url");

user = prop.getProperty("un");

pwd = prop.getProperty("up");

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

? ? }

? ??

? ? //獲取數(shù)據(jù)庫連接對象的方法

? ? public static Connection getConn(){

? ? Connection conn = null;

? ? try {

Class.forName(driverName);

conn = DriverManager

.getConnection(url,user,pwd);

} catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

}? ?

? ? return conn;

? ? }

? ??

? ? public static void close(ResultSet

? ? rs,PreparedStatement pstm

? ? ,Connection conn){

? ? ? ? try {

? ? ? ? if(rs != null) {

? ? ? ? ? ? rs.close();

? ? ? ? ? ? }

? ? ? ? ? ? if(pstm != null) {

? ? ? ? ? ? pstm.close();

? ? ? ? ? ? }

? ? ? ? ? ? if(conn != null) {

? ? ? ? ? ? conn.close();

? ? ? ? ? ? }

? ? ? ? } catch(Exception e) {

? ? ? ? e.printStackTrace();

? ? ? ? }

? ? }

}

dn=com.mysql.jdbc.Driver

url=jdbc:mysql://localhost:3306/firstjsp?useUnicode=true&characterEncoding=UTF-8

un=root

up=root

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<%

? ? String path = request.getContextPath();

? ? String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

<%@page import="com.SSHC.bean.User"%>

<%@page import="com.SSHC.DAO.UserDao"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

? ? <head>

? ? ? ? <base hreff="<%=basePath%>">

? ? ? ? <title></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="rs" method="post">

? ? ? ? <input type="text" name="act" placeholder="請輸入賬號" />

? ? ? ? <div style="color:red;">${msg }</div>

? ? ? ? <input type="submit" value="提交" />

? ? ? ? </form>

? ? </body>

</html>

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<%

? ? String path = request.getContextPath();

? ? String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

? ? <head>

? ? ? ? <base hreff="<%=basePath%>">

? ? ? ? <title></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>

? ? ? ? <h1>${msg }</h1>

? ? </body>

</html>



create table User(

id int primary key auto_increment,



act varchar(100) ,


pwd varchar(100) ,

sex char(100) ,


brith date,



hobbys? ?varchar(100)


);









——————


自己寫的題目等:

打印出訪問Servlet的次數(shù)和使用“出生”和“銷毀”的方法


package com.jy;


import java.io.IOException;

import javax.servlet.ServletException;

import javax.servlet.annotation.WebServlet;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;


/**

?* Servlet implementation class MyServlet

?*/

@WebServlet("/ms")

public class MyServlet extends HttpServlet {

private static final long serialVersionUID = 1L;

private Integer count = 0;

? ? ? ?

? ? /**

? ? ?* @see HttpServlet#HttpServlet()

? ? ?*/

? ? public MyServlet() {

? ? ? ? super();

? ? ? ? // TODO Auto-generated constructor stub

? ? }

? ? //當(dāng)servlet被銷毀時調(diào)用這個方法

? ? //一般就是項目重啟時會被銷毀

@Override

public void destroy() {

// TODO Auto-generated method stub

System.out.println("被銷毀了");

}

? ? //當(dāng)servlet被創(chuàng)建出來的時候調(diào)用

//在整個的servlet的生命周期中只會調(diào)用一次

@Override

public void init() throws ServletException {

// TODO Auto-generated method stub

System.out.println("我出生啦");

}


@Override

protected void service(HttpServletRequest arg0, HttpServletResponse arg1)

throws ServletException, IOException {

// TODO Auto-generated method stub

super.service(arg0, arg1);

}

/**

* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)

*/

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

// TODO Auto-generated method stub

this.doPost(request, response);

}


/**

* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)

*/

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

// TODO Auto-generated method stub

count ++;

System.out.println(count);

}


}




例子:


1
2
3
4



下面是用于讓”銷毀“方法,讓我們可以看到執(zhí)行效果的方法,但有時不建議改bat,怕忘記改回來:

5
6
7
8
9
10





學(xué)習(xí)筆記:


一、HTTP協(xié)議

二、servlet


HTTP協(xié)議:超文本傳輸協(xié)議,文本代表字符串的意思,超文本代表圖片,音頻和視頻

游戲的鼻祖:泥巴游戲mud,它是一個純的文字游戲。

網(wǎng)絡(luò)上面發(fā)送這些超文本時,就必須要遵守一定的規(guī)則,這樣其他的人才能夠接收到

的超文本內(nèi)容,這個規(guī)則就叫超文本傳輸協(xié)議

Javaweb就遵循HTTP協(xié)議

HTTP協(xié)議有兩個非常重要的請求方式:get請求方式和post請求方式

404:找不到你需要的資源(jsp頁面,html頁面以及servlet),訪問路徑如果不會就

會報這個錯誤

500:表示后臺代碼出現(xiàn)了錯誤(java代碼)

200:表示請求成功了


Servlet:由java代碼編寫的一個小服務(wù)程序,它的作用非常的廣泛,可以實現(xiàn)非常多

的功能,登錄注冊增刪改查,附件上傳下載,導(dǎo)出excel文件,servlet其實就是一個java類。

使用servlet:servlet雖然是一個java類,但是不能夠直接運行。它必須啟動tomcat服

務(wù)器以后才能運行。

創(chuàng)建一個servlet,運行它的時候在后臺打印Hello world.

1、創(chuàng)建一個java類,讓它繼承HttpServlet類,重寫doGet和doPost方法。

2、打開web.xml配置文件,對servlet進(jìn)行配置。


快捷配置一個servlet:


當(dāng)你在瀏覽器地址欄直接輸入一個servlet的訪問路徑時,調(diào)用的是doGet方法

當(dāng)在表單中運行一個servlet時,會根據(jù)表單的method屬性來決定是調(diào)用doPost方法還是doGet方法。

post提交方式提交表單數(shù)據(jù)時,提交的數(shù)據(jù)不會顯示在瀏覽器地址欄中

get提交方式提交表單數(shù)據(jù)時,提交的數(shù)據(jù)會顯示在瀏覽器地址欄中。

post提交方式比較安全的。

get提交方式提交的數(shù)據(jù)量比較小

post提交方式提交的數(shù)據(jù)量比較大


一、servlet生命周期

二、init和destroy

三、loadonstartup servlet

四、servlet頁面跳轉(zhuǎn)方式


創(chuàng)建servlet的方式:

1、創(chuàng)建一個java類,讓他繼承HttpServlet,然后在web.xml中添加一段配置代碼。

2、new servlet就可以創(chuàng)建出來


在項目中,創(chuàng)建servlet實例的時機(jī):

1、當(dāng)項目啟動以后的第一個用戶請求這個servlet時,就會new出一個servlet實例,

當(dāng)這個用戶使用完以后,servlet實例不會消失,會一直保存在項目中,當(dāng)下一次有用戶再次請求這個servlet的時候,就不會再new這個servlet,會直接使用前面保存在項目中的servlet實例。

2、隨著項目啟動,會自動的創(chuàng)建servlet


第二個用戶也是訪問這個servlet,不會再new出一個servlet實例了,它會直接使用第

一次new出來的servlet實例

loadonstartup servlet:隨著項目的啟動會自動運行的


通過servlet來進(jìn)行頁面跳轉(zhuǎn):

創(chuàng)建一個LoginServlet,運行這個servlet以后能夠跳轉(zhuǎn)到login.jsp頁面


jsp頁面每一個頁面其實都是一個servlet

jsp頁面轉(zhuǎn)換成servlet類以后的源代碼可以在tomcat服務(wù)器中的work目錄下找到


jsp頁面:在html代碼中寫java代碼

servlet:在java代碼中寫html代碼


實現(xiàn)重名驗證





Java web:重名驗證load-on-startup servlet生命周期,學(xué)習(xí)筆記和代碼例子【詩書畫唱】的評論 (共 條)

分享到微博請遵守國家法律
长寿区| 福鼎市| 桐城市| 突泉县| 青龙| 共和县| 留坝县| 大同县| 阿拉尔市| 新津县| 诸城市| 紫金县| 葫芦岛市| 嘉祥县| 临安市| 清水河县| 修武县| 辽源市| 夏河县| 新干县| 离岛区| 红安县| 大同市| 济宁市| 扶绥县| 长汀县| 桓台县| 清涧县| 二连浩特市| 德化县| 永靖县| 阿荣旗| 盘山县| 通许县| 丹凤县| 霸州市| 清流县| 宁远县| 雅江县| 马龙县| 阿拉尔市|