美文网首页
Servlet API 精选

Servlet API 精选

作者: CPU_Easy | 来源:发表于2018-10-28 00:34 被阅读0次

HttpSerlvet 常用方法:

getServletContext():    获取ServletContext对象,即JSP内置对象中的application对象

getServletName():    获取Servlet配置时声明在Web应用内部使用的名字

getInitParameter(String name):    获取Servlet配置时提供的名为name的参数值

HttpSerlvetRequest 常用方法:

getRequestURL():获取请求的URL地址,包括协议名,服务器名,端口号和所请求服务的路径,但不包含请求时所带的参数

getRequestURI():获取所请求服务的路径

getContextPath():获取Web应用的根路径

getServletPath():获取Servlet的访问地址

getParameter(String name):    获得名为name的参数的单个值

getParameterValues(String name):    获得名为name的参数的多个值

getAttribute(String name):    获得名为name的属性值

setAttribute(String name,String value):    设置名为name的属性值为value

getSession():    获取session对象

getRequestDispatcher(String path):获取请求转发对象,转向地址为path。所获得的RequestDispatcher对象的forward()方法实现真正的跳转

HttpSerlvetResponse 常用方法:

setContentType(String type):    设置响应的内容类型为type

setCharacterEncoding(String charset):    设置响应的编码字符集为charset

getWriter():    返回一个PrintWriter对象,利用这个对象可以向客户端输出文本,这个对象的作用类似于JSP的内置对象out

sendRedirect(String location):    向客户端发送一个重定向请求,地址为location

相关文章

网友评论

      本文标题:Servlet API 精选

      本文链接:https://www.haomeiwen.com/subject/exaytqtx.html