当前位置:网站首页>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;
}
}
边栏推荐
- Can gbase 8A view the location of SQL statement history?
- Leetcode: Shortest Word Distance II
- Anaconda uses China University of science and technology source
- 亿咖通科技通过ISO27001与ISO21434安全管理体系认证
- Bugku's Ah Da
- [detailed explanation of Huawei machine test] character statistics and rearrangement
- 爱可可AI前沿推介(7.5)
- Photoshop插件-动作相关概念-ActionList-ActionDescriptor-ActionList-动作执行加载调用删除-PS插件开发
- Reasons and solutions for redis cache penetration and cache avalanche
- Bugku's eyes are not real
猜你喜欢
![P6183 [USACO10MAR] The Rock Game S](/img/f4/d8c8763c27385d759d117b515fbf0f.png)
P6183 [USACO10MAR] The Rock Game S

Talking about how dataset and dataloader call when loading data__ getitem__ () function

Aike AI frontier promotion (7.5)
![P6183 [USACO10MAR] The Rock Game S](/img/f4/d8c8763c27385d759d117b515fbf0f.png)
P6183 [USACO10MAR] The Rock Game S

Behind the ultra clear image quality of NBA Live Broadcast: an in-depth interpretation of Alibaba cloud video cloud "narrowband HD 2.0" technology

sql server学习笔记

How to paste the contents copied by the computer into mobaxterm? How to copy and paste

市值蒸发超百亿美元,“全球IoT云平台第一股”赴港求生

两个BI开发,3000多张报表?如何做的到?

数据库学习——数据库安全性
随机推荐
Talking about how dataset and dataloader call when loading data__ getitem__ () function
【数组和进阶指针经典笔试题12道】这些题,满足你对数组和指针的所有幻想,come on !
市值蒸发超百亿美元,“全球IoT云平台第一股”赴港求生
Cartoon: programmers don't repair computers!
Bugku easy_ nbt
mapper. Comments in XML files
Stop B makes short videos, learns Tiktok to die, learns YouTube to live?
Select sort and bubble sort
Does maxcompute have SQL that can query the current storage capacity (KB) of the table?
Calculate weight and comprehensive score by R entropy weight method
危机重重下的企业发展,数字化转型到底是不是企业未来救星
Common MySQL interview questions
Leetcode: Shortest Word Distance II
Magic methods and usage in PHP (PHP interview theory questions)
Common PHP interview questions (1) (written PHP interview questions)
R 熵权法计算权重及综合得分
Bugku's eyes are not real
Surpass palm! Peking University Master proposed diverse to comprehensively refresh the NLP reasoning ranking
Shanghai under layoffs
两个BI开发,3000多张报表?如何做的到?