当前位置:网站首页>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;
}
}
边栏推荐
- 可转债打新在哪里操作开户是更安全可靠的呢
- Creation and optimization of MySQL index
- 【华为机试真题详解】字符统计及重排
- Two Bi development, more than 3000 reports? How to do it?
- Magic methods and usage in PHP (PHP interview theory questions)
- Run faster with go: use golang to serve machine learning
- Huiyuan, 30, is going to have a new owner
- Ctfshow web entry information collection
- Talk about your understanding of microservices (PHP interview theory question)
- [detailed explanation of Huawei machine test] happy weekend
猜你喜欢

Coding devsecops helps financial enterprises run out of digital acceleration

Creation and use of thymeleaf template

亿咖通科技通过ISO27001与ISO21434安全管理体系认证

729. My schedule I: "simulation" & "line segment tree (dynamic open point) &" block + bit operation (bucket Division) "

Bugku's eyes are not real

Two Bi development, more than 3000 reports? How to do it?

Common MySQL interview questions

Bugku telnet

Crud of MySQL

qt creater断点调试程序详解
随机推荐
Common redis data types and application scenarios
[JVM] operation instruction
"Sequelae" of the withdrawal of community group purchase from the city
【数组和进阶指针经典笔试题12道】这些题,满足你对数组和指针的所有幻想,come on !
Stop B makes short videos, learns Tiktok to die, learns YouTube to live?
sql server char nchar varchar和nvarchar的区别
Bugku's steganography
Bugku's Ping
计算中间件 Apache Linkis参数解读
DVWA range clearance tutorial
NBA赛事直播超清画质背后:阿里云视频云「窄带高清2.0」技术深度解读
Fr exercise topic --- comprehensive question
TS所有dom元素的类型声明
CPU design related notes
mapper. Comments in XML files
Where is the operation of convertible bond renewal? Is it safer and more reliable to open an account
Can I pass the PMP Exam in 20 days?
我这边同时采集多个oracle表,采集一会以后,会报oracle的oga内存超出,大家有没有遇到的?
危机重重下的企业发展,数字化转型到底是不是企业未来救星
你童年的快乐,都是被它承包了