`
ren2881971
  • 浏览: 108374 次
社区版块
存档分类
最新评论

Servlet&Jsp javax.servlet.http包中的内容

    博客分类:
  • j2ee
阅读更多
javax.servlet.http:
Interface HttpServletRequest
this interface extends the interface ServletRequest to provide request interformation for the http  HTTP servlets.

The servlet container creates an HttpServletRequest object and passes it as an argument to the servlet's service methods (doGet, doPost, etc).


Method:
getContextPath(): obtain the project's name '/example'
getCookies():return an array containing all of the Cookie objects the client send with this request
getHeader():
getMethod()
getPathInfo()
getRequestSessionId()可能跟session的id不同,如果客户没有指定一个会话ID,此方法返回null。
getRequestURI() 获得项目的http 请求的uri
getRequestURL()获得url
ps: url和uri的区别  url是通过浏览器访问的地址名称,uri是项目路径没有http和网络地址相关信息
getSession()  获得当前session
getSession(boolean create) 如果create=true 则建立一个新的session,create=false则返回null或者获得当前session

Servlet 3.0中增加的 authenticate().login(),logout()这三个方法实在不知道怎么用啊。。第一次觉得网上的资料好少。


Interface HttpServletResponse
addCookie(Cookie cookie)
addHeader(String name,String value)
setRedirect(String loaction)
encodeURL(String url) return String:重写url 在cookie被当前大多数浏览器禁用的时候,可以选择重写url这方式来报错session的跟踪。
Interface HttpSession:

Method:
getAttribute()
setAttribute()
getCreationTime()
getId()
getMaxInactiveInterval()
setMaxInactiveInterval()
getServletContext()
invalidate():是当前的session失效,如果调用这个方法后 在执行有关session的操作
如session.getAttribute就是报500的错
isNew()
removeAttribute()

Interface HttpSessionAttributeListener:

对session中的属性情况进行了监听
method:
attributeAdded(HttpSessionAttributeEvent)
attributeRemoved(HttpSessionAttributeEvent)
attributeReplaced(HttpSessionAttributeEvent)

Interface HttpSessionListener
对session的初始化和销毁情况进行了监控
method:
sessionCreated(HttpSessionEvent)
sessionDestroyed(HttpSessionEvent)

Interface HttpSessionBindingListener
对绑定到session属性的对象进行了监听
valueBound(HttpSessionBindingEvent)
valueUnbound(HttpSessionBindingEvent)

HttpSessionActivationListener
是对不同VM之间session的交互的监听
method:
sessionDidActivate(HttpSessionEvent)
sessionWillPassivate(HttpSessionEvent)

常用类:
Cookie
HttpServlet
<-----------------------以前没用过的------------->
HttpServletRequestWrapper
HttpServletResponseWrapper
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics