3.ServletContext的常用API
1)java.net.URL getResource(java.lang.String path)
Returns a URL to the resource that is mapped to the given path.
2(void setAttribute(java.lang.String name, java.lang.Object object)
Binds an object to a given attribute name in this ServletContext.
3)void removeAttribute(java.lang.String name)
Removes the attribute with the given name from this ServletContext.
4.在文本.xml文件中配置全局共享数据。
5.向浏览器输出文件代码示例
Extends the ServletRequest intece to provide request information for HTTP servlets.
The servlet container creates an HttpServletRequest object and passes it as an argument to the servlet's service methods (doGet, doPost, etc).
javax.servlet.http
Intece HttpServletRequest
All Superinteces:
ServletRequest
All Known Implementing Classes:
HttpServletRequestWrapper
1.)java.lang.String getRequestURI()
Returns the part of this request's URL from the protocol name up to the query string in the first line of the HTTP request. 获取所请求的服务路径,
例如appname/url-pattern
2)java.lang.StringBuffer getRequestURL()
Reconstructs the URL the client used to make the request. 获取请求的URL地址,包括协议名、服务器名、端口号和所请求的服务的路径,但不包括请求时所带事务参数。例如::7405/bbs/servlet/FirstServlet
3)java.lang.String getServletPath()
Returns the part of this request's URL that calls the servlet. 获取Servlet的访问地址,例如url-pattern
4).java.lang.String getContextPath()
Returns the portion of the request URI that indicates the context of the request.获取web应用的根路径,例如/appname
5)HttpSession getSession()
Returns the current session associated with this request, or if the request does not have a session, creates one.
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/ruanjian/article-36808-8.html
使得多余的男性成为女性的消费品
等得太久了