当前位置:网站首页>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;
}
}
边栏推荐
- mapper. Comments in XML files
- Huiyuan, 30, is going to have a new owner
- 美团优选管理层变动:老将刘薇调岗,前阿里高管加盟
- 12 MySQL interview questions that you must chew through to enter Alibaba
- 机器学习笔记 - 灰狼优化
- 亿咖通科技通过ISO27001与ISO21434安全管理体系认证
- Stop B makes short videos, learns Tiktok to die, learns YouTube to live?
- P6183 [USACO10MAR] The Rock Game S
- GPS原始坐标转百度地图坐标(纯C代码)
- easyOCR 字符識別
猜你喜欢
729. My schedule I: "simulation" & "line segment tree (dynamic open point) &" block + bit operation (bucket Division) "
Your childhood happiness was contracted by it
Ten billion massage machine blue ocean, difficult to be a giant
Redis' transaction mechanism
Crud of MySQL
Reasons and solutions for redis cache penetration and cache avalanche
Huiyuan, 30, is going to have a new owner
1330: [example 8.3] minimum steps
Creation and use of thymeleaf template
P6183 [USACO10MAR] The Rock Game S
随机推荐
JMeter performance test: serveragent resource monitoring
Selection and use of bceloss, crossentropyloss, sigmoid, etc. in pytorch classification
Talk about your understanding of microservices (PHP interview theory question)
Crud of MySQL
easyOCR 字符识别
Photoshop插件-动作相关概念-ActionList-ActionDescriptor-ActionList-动作执行加载调用删除-PS插件开发
市值蒸发超百亿美元,“全球IoT云平台第一股”赴港求生
mapper. Comments in XML files
Ctfshow web entry information collection
go学习 ------jwt的相关知识
Common PHP interview questions (1) (written PHP interview questions)
729. My schedule I: "simulation" & "line segment tree (dynamic open point) &" block + bit operation (bucket Division) "
Can I pass the PMP Exam in 20 days?
Bugku's steganography
easyOCR 字符識別
Bugku's eyes are not real
Can gbase 8A view the location of SQL statement history?
TS所有dom元素的类型声明
"Sequelae" of the withdrawal of community group purchase from the city
Huiyuan, 30, is going to have a new owner