一、servlet
servlet 生命周期
加裁,实例化
初使化init()
service(): doGet()/doPost()
销毁 destory()
servlet 创建
MyServlet.java
extends HttpServlet{
void doGet(HttpServletRequest,HttpServletResponse)}
web.xml
http://localhost:8080/rest/show.jsp
/servlet/foodservlet
response.setContentType("text/html;charSet=GBK")
//response的内容类型和编码
路径问题:“/”绝对路径
1)
<a href=""
<form action="/rest/foodservlet"
<%response.sendTedirect("/")%>以http://localhost:8080开始
<form action="${pageContext.request.contextPath}"> //取对像/rest
在html中有存在<base>标签
2)
http://localhost:8080/rest
<jsp:forward page="/show.jap">
<%request.getRequestDispather("/show.jsp").forward(request,response);
%>
注意:配制文件要配好 在web.xml中
二、
HttpSession---生命周期
创建 : 第一次请求
销毁 : 1)超时2)浏览器销毁 3)session.invalidate();====离开
ServletContext
获取: request.getSession(); //不存在会新建SESSION
request.getSession(true); //不存在会新建SESSION
request.getSession(false); //不存在就会返回NUll
数据存取(通信域)
page:
request:
session:
application:
setAttribute(String key,object);
object.getAttribute(key);
Iterator i=values().iterator();
while(i.netxt())
Map --- key/value
Set keySet()
Collection values();
Conlection ---vlue
.add(object)
servlet 生命周期
加裁,实例化
初使化init()
service(): doGet()/doPost()
销毁 destory()
servlet 创建
MyServlet.java
extends HttpServlet{
void doGet(HttpServletRequest,HttpServletResponse)}
web.xml
http://localhost:8080/rest/show.jsp
/servlet/foodservlet
response.setContentType("text/html;charSet=GBK")
//response的内容类型和编码
路径问题:“/”绝对路径
1)
<a href=""
<form action="/rest/foodservlet"
<%response.sendTedirect("/")%>以http://localhost:8080开始
<form action="${pageContext.request.contextPath}"> //取对像/rest
在html中有存在<base>标签
2)
http://localhost:8080/rest
<jsp:forward page="/show.jap">
<%request.getRequestDispather("/show.jsp").forward(request,response);
%>
注意:配制文件要配好 在web.xml中
二、
HttpSession---生命周期
创建 : 第一次请求
销毁 : 1)超时2)浏览器销毁 3)session.invalidate();====离开
ServletContext
获取: request.getSession(); //不存在会新建SESSION
request.getSession(true); //不存在会新建SESSION
request.getSession(false); //不存在就会返回NUll
数据存取(通信域)
page:
request:
session:
application:
setAttribute(String key,object);
object.getAttribute(key);
Iterator i=values().iterator();
while(i.netxt())
Map --- key/value
Set keySet()
Collection values();
Conlection ---vlue
.add(object)