有关JSP的总结(9大内置对象)

一、九大内置对象
1、
1.1 pageContext:内置对象的集大成者,很少使用。
config:指定jsp页面初始配置的 Servlet
page:当前jsp实例化的对象(java.lang.Object page=this)
exception:处理页面异常。
源码截图:在这里插入图片描述
1.2
session
application
out
request
response
2、
request.getScheme() 返回当前链接使用的协议;一般应用返回http;SSL返回https;

String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    <base href="<%=basePath%>">

**request.getSchema()**可以返回当前页面使用的协议,http 或是 https;

**request.getServerName()**可以返回当前页面所在的服务器的名字;

**request.getServerPort()**可以返回当前页面所在的服务器使用的端口,就是80;

**request.getContextPath()**可以返回当前页面所在的应用的名字;
request对象常用方法
String getParameter(String name);//根据表单组件名称获取提交数据
String[] getParameterValues(String name);//获取表单组件对应多个值时的请求数据
void setCharacterEncoding(String charset);//指定每个请求的编码
RequestDispatcher getRequestDispatcher(String path);//返回一个requestDispatcher对象,该对象的forward()方法用来转发请求。

猜你喜欢

转载自blog.csdn.net/pojpoj/article/details/89365694