当前位置:网站首页>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;
}
}
边栏推荐
- Bugku's steganography
- Leetcode: Shortest Word Distance II
- Reconnaissance des caractères easycr
- Talk about your understanding of microservices (PHP interview theory question)
- Super wow fast row, you are worth learning!
- Bugku easy_ nbt
- [C question set] of Ⅷ
- Run faster with go: use golang to serve machine learning
- Common MySQL interview questions (1) (written MySQL interview questions)
- What are the domestic formal futures company platforms in 2022? How about founder metaphase? Is it safe and reliable?
猜你喜欢

Creation and optimization of MySQL index

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

IPv6与IPv4的区别 网信办等三部推进IPv6规模部署

NBA赛事直播超清画质背后:阿里云视频云「窄带高清2.0」技术深度解读

Under the crisis of enterprise development, is digital transformation the future savior of enterprises

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

MongDB学习笔记

Stop B makes short videos, learns Tiktok to die, learns YouTube to live?

MySQL----函数

两个BI开发,3000多张报表?如何做的到?
随机推荐
Magic methods and usage in PHP (PHP interview theory questions)
【C 题集】of Ⅷ
How can I quickly check whether there is an error after FreeSurfer runs Recon all—— Core command tail redirection
[recruitment position] infrastructure software developer
Ctfshow web entry information collection
Reconnaissance des caractères easycr
CPU design practice - Chapter 4 practice task 3 use pre delivery technology to solve conflicts caused by related issues
Change multiple file names with one click
百亿按摩仪蓝海,难出巨头
Interview shock 62: what are the precautions for group by?
Stop B makes short videos, learns Tiktok to die, learns YouTube to live?
Install and configure Jenkins
危机重重下的企业发展,数字化转型到底是不是企业未来救星
Huiyuan, 30, is going to have a new owner
Long list optimized virtual scrolling
JMeter performance test: serveragent resource monitoring
IPv6与IPv4的区别 网信办等三部推进IPv6规模部署
Brief introduction of machine learning framework
NBA赛事直播超清画质背后:阿里云视频云「窄带高清2.0」技术深度解读
Common MySQL interview questions