当前位置:网站首页>Severlet learning foundation
Severlet learning foundation
2022-07-05 15:16:00 【Add gold development】
<load-on-satrtup>x</load-on-satrtup> x Small first
Httpservrlet request: The scope of action is only in one request
request.setAttribte(); Given value .
Four ways :
setAttbute..();
HttpSession session :
HttpSession session=request.getSession(); Value .
1, stay respose.getSession , obtain
2, It works when the browser or server is not turned off
3,<session-time></session->
4, perform session.invalidate(); It will clear the data and invalidate
5,<session-config><session-timeout>10</session-timeout></session-config>
Wait for refresh time difference (10 minute )
6,session.getId(); The server and browser are not paired session Invalid ! And it doesn't repeat !
Server browser relationship !session.getId() !SessionID()....>
The browser sends a request to the server , The server first judges , Whether the request carries a SessionID value
If this request does not carry one SessionID value , The server knows , This is the first time to access this server
The browser starts a session with the server
The server will respond to the request at the same time , Will produce a SessionID, As the identification of this session
Put this again. SessionID To browser , Browsers have one SessionID 了
When accessing the server again , The browser will carry that SessionID, Sent to the server
The server first determines whether the request carries a SessionID value , Now there is , Represents that this is not a request for a new session
If the time between two browser requests is too long , The waiting time of the server is exceeded , The server will delete this session object
After deleting , Send it to the server again , Because there is no such thing in the server session Object , You can't judge whether the request carries SessionID value
That is to say, I can't judge , Think this is the beginning of a new conversation , There will be another SessionID, As the logo of this new Conference
Put this again SessionID To browser , The browser has a new SessionID 了
At the beginning of the session , The server will automatically allocate a space (session object ),SessionID It's just session In the object
severletConfig
Interface be-all severlet Can be called ,severletConfig A project is shared
ServletConfig fig=this.getServletConfig();
fig.getInitParameter(String src); Get all the files in the current directoryget : SeverletConfig fig=this.getSeverletConfig();
Step by step : stay web It is defined <init-param><param-name>name</param-name>
<param-value>abc</param-value>
</init-param>
Get value fig.getInitParameterName(); Get all
fig,getSeverLetContext();, To name one
get :SeverletConfig fig=this.getSeverLetContext();
stay web Debugging code in
<!-- Jump -->
<servlet>
<servlet-name>severlet</servlet-name>
<servlet-class>testSeverlet.severlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>severlet</servlet-name>
<url-pattern>/severlet</url-pattern>
</servlet-mapping>
<!-- session test -->
<servlet>
<servlet-name>sessionT0</servlet-name>
<servlet-class>sessionT.sessionT0</servlet-class>
<!-- Set up severletConfig -->
<init-param><param-name>name</param-name>
<param-value>abc</param-value>
</init-param>
<init-param><param-name>jdbc</param-name>
<param-value>jdbc://127.0.0.1:8080/std</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>sessionT0</servlet-name>
<url-pattern>/sessionT0</url-pattern>
</servlet-mapping>
<!-- filter -->
<filter>
<filter-name>severletT1</filter-name>
<filter-class>sessionT.severletT1</filter-class>
</filter>
<filter-mapping>
<filter-name> severletT1</filter-name><!-- route -->
<url-pattern>/*</url-pattern><!-- Filtered range -->
</filter-mapping>
stay class File code :
first class Debug class :
public class severletT1 extends HttpServlet implements Filter{
// @Override
// throws ServletException, IOException {
// // TODO Auto-generated method stub
// doPost(request, response);
//}
// @Override
// protected void doPost(HttpServletRequest request, HttpServletResponse response)
// throws ServletException, IOException {
// // TODO Auto-generated method stub
ServletConfig fig2=this.getServletConfig();
System.out.println(fig2.getInitParameter("name"));
System.out.println(fig2.getInitParameterNames());
ServletContext fig=this.getServletContext();
System.out.println(fig.getAttribute("jdbc"));
//
// }
//
@Override
public void destroy() {
// TODO Auto-generated method stub
super.destroy();
}
@Override
public void doFilter(ServletRequest arg0, ServletResponse arg1,
FilterChain arg2) throws IOException, ServletException {
// TODO Auto-generated method stub
System.out.println("aandjkashdgasdgasjhdga");
}
@Override
public void init(FilterConfig arg0) throws ServletException {
// TODO Auto-generated method stub
}
the second class Debug class :
public class sessionT0 extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
HttpSession session=request.getSession();
request.setAttribute("name","gg");
request.setAttribute("pwd","123456");
session.setAttribute("name1","hh");
session.setAttribute("pwd1", "123hh");
System.out.println(session.getId());
//session.invalidate(); // invalid
ServletConfig fig=this.getServletConfig();
System.out.println(fig.getInitParameter("jdbc"));
System.out.println(fig.getInitParameterNames());
ServletContext fig2=this.getServletContext();
fig2.getAttribute("jdbc");
// request.getRequestDispatcher("SE.jsp").forward(request, response);
// return;
}
}
边栏推荐
- Go learning ----- relevant knowledge of JWT
- Redis' transaction mechanism
- qt creater断点调试程序详解
- Photoshop插件-动作相关概念-非加载执行动作文件中动作-PS插件开发
- Aike AI frontier promotion (7.5)
- Garbage collection mechanism of PHP (theoretical questions of PHP interview)
- Two Bi development, more than 3000 reports? How to do it?
- Redis distributed lock principle and its implementation with PHP (1)
- Easyocr character recognition
- The difference between SQL Server char nchar varchar and nvarchar
猜你喜欢
Photoshop plug-in action related concepts actionlist actiondescriptor actionlist action execution load call delete PS plug-in development
qt creater断点调试程序详解
Creation and optimization of MySQL index
超越PaLM!北大硕士提出DiVeRSe,全面刷新NLP推理排行榜
Garbage collection mechanism of PHP (theoretical questions of PHP interview)
Surpass palm! Peking University Master proposed diverse to comprehensively refresh the NLP reasoning ranking
Crud of MySQL
MySQL之CRUD
Mysql---- function
两个BI开发,3000多张报表?如何做的到?
随机推荐
Select sort and bubble sort
Bugku's Ah Da
想问下大家伙,有无是从腾讯云MYSQL同步到其他地方的呀?腾讯云MySQL存到COS上的binlog
Huawei Hubble incarnation hard technology IPO harvester
Creation and optimization of MySQL index
IPv6与IPv4的区别 网信办等三部推进IPv6规模部署
做研究无人咨询、与学生不交心,UNC助理教授两年教职挣扎史
Garbage collection mechanism of PHP (theoretical questions of PHP interview)
Thymeleaf uses background custom tool classes to process text
Interpretation of Apache linkage parameters in computing middleware
Huiyuan, 30, is going to have a new owner
市值蒸发超百亿美元,“全球IoT云平台第一股”赴港求生
Reasons and solutions for redis cache penetration and cache avalanche
Surpass palm! Peking University Master proposed diverse to comprehensively refresh the NLP reasoning ranking
Redis distributed lock principle and its implementation with PHP (2)
Aike AI frontier promotion (7.5)
P6183 [USACO10MAR] The Rock Game S
[12 classic written questions of array and advanced pointer] these questions meet all your illusions about array and pointer, come on!
漫画:程序员不是修电脑的!
I want to inquire about how to ensure data consistency when a MySQL transaction updates multiple tables?