request 请求:
String getQueryString()???????????????????? 取得URI中的查询字符串(后的字符串)
String x(String name)?????????????????????? 取得参数字符串所对应的字符串参数值
String[] getParameterValues(String name)??? 取得参数字符串所对应的所有字符串参数值
Map getParameterMap()?????????????????????? 取得一个要求参数的Map
Enumeration getParameterNames()???????????? 取得所有的参数名称
=============================分隔线=============================
request内置对象中用于实现request作用域存储的方法
void setAttribute(String name , Object value);
??? 将Object对象以name的名称进行request作用域的存储
Object getAttribute(String name);
??? 通过name获得存储在request作用域中的对象
void removeAtribute(String name);
??? 通过name删除存储在request作用域中的对象
Enumeration getAttributeNames();
??? 获得所有存储在request作用域中的属性名
JSP中获得request内置对象的其它方式 pageContext.getRequest();
JSP转发是指:JSP容器将使用一个内部的方法来调用目标页面,新的页面继续
处理同一个请求,而浏览器将不会知道这个过程。所以它只能在同一个JavaWeb应用
中使用,所以可以共享request范围内的数据。
使用如下方法实现JSP转发:
RequestDispatcher rd = request.getRequestDispatcher(URL);
rd.forward(request, response);
参数URL中使用"/"开头,表示的是当前JavaWeb应用程序的根目录。
转发只能在当前Web应用中进行请求响应,而重定向可以在不同
Web应用中进行请求响应。
转发中URL以"/"开头,表示的是当前JavaWeb应用程序的根目录。重定向中URL
以"/"开头,,它是相对于所有JavaWeb应用的根目录。
重定向的访问过程结束后,浏览器地址栏中显示的URL会发生改变,由初始的
URL地址变成重定向的目标URL;而请求转发过程结束后,浏览器地址栏保持初始的
URL地址不变。
转发的调用者与被调用者之间共享相同的request 对象和response对象,它们
属于同一个访问请求和响应过程,所以request对象共享;而重定向的调用者与被调
用者使用各自的request对象和response 对象,它们属于两个独立的访问请求和响应
过程,所以request对象不共享。
无论是转发还是重定向,都不能以有内容实际输出到客户端。如
果缓冲区中已经有了一些内容,这些内容将被从缓冲区中清除。
=============================分隔线=============================
假定你的web application 名称为news,你在浏览器中输入请求路径:
http://localhost:8080/news/main/list.jsp
则执行下面向行代码后打印出如下结果:
1、 System.out.println(request.getContextPath());?? 项目虚拟名称
打印结果:/news
2、System.out.println(request.getServletPath());
打印结果:/main/list.jsp
3、 System.out.println(request.getRequestURI());
打印结果:/news/main/list.jsp
4、System.out.println(request.getRequestURL());
打印结果:http://localhost:8080/news/main/list.jsp
5、 System.out.println(request.getRealPath("/"));
打印结果:F:\Tomcat 6.0\webapps\news\test
request.getServerName(); 服务器名称(类似 localhost)
request.getServerPort();? 端口
request.getScheme();????? 协议名称
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
path = request.getContextpath()有什么用
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()
+":"+request.getServerPort()+path+"/";
%>
那么他的含义就是为了得到一个路径,做动态网站时,需要提交form表单在表单
的action里面就会这样来写
action="<%=path %>/add.do" 这样来提交到相应的servlet中去,这样可以避免
路径的错误,而采用这样的相对路径会更好些
详细解决方案
request 作用域 惯用方法
热度:255 发布时间:2013-05-02 09:39:29.0
相关解决方案
- request.setAttribute("list" "''");该怎么解决
- request.setAttribute("message" message)不能传int参数,该怎么处理
- RequestDispatcher rd = request.getRequestDispatcher跳转页面出现有关问题
- request.setAttribute("message" message)不能传int参数,该怎么解决
- 为何jsp request.getParameter取不到值,但request.getQueryString()却有值呢
- 求老妪能解解释Response、Request
- request.setAttribute()有关问题
- @Context HttpServletRequest request,@Context HttpServletResponse response,该如何解决
- List items = upload.parseRequest(request);替空kindeditor SpringMvc
- 急紧急十分紧急JSP,「focus="<%= JspUtil.getFirstProperty(request, null) %>」哪位高手给解释上这句话的作用?一有答案立即结帖
- struts2<s:if test=${pb.pageTotal>0}>出现有关问题 如果小弟我这样写是正确的<s:if test=#request.pb.pageT
- 如何找到http 404异常发生时的 Request URL
- request.getSession报java.lang.NullPointerException,该如何解决
- request.getCookies()方法得不到cookie,只得到一个内存cookie.解决方案
- request.getParameter会丢失一些符号的有关问题
- request.getParameter("target");是什么意思,该如何解决
- struts2关于ActionContext.getContext.get("request")有关问题
- Struts2 的 Action 类里如何创建 session request response out 对象
- request.getRequestDispatcher中转页面出错
- request.getSession().getAttribute("requestPath")为什么得到的是NULL,其它的方法中可以得到URL解决思路
- RA layer request failed解决方案
- request.getRequestURL()跟request.getRequestURI()有什么区别
- request.getAttribute 传值取值有关问题
- django rest framework 入门二——Request and Response
- temp = Request.QueryString["mid"]; 如何取不了值
- Request.Url.Host 获取请求地址,该如何解决
- C#开发的网页,捕捉ystem.Web.HttpException (0x80004005): Request timed out.错误
- Request.Cookies有关问题
- Request.Browser.BrowserName 会获取搜索引擎蜘蛛的的名称吗
- mvc:Request.QueryString[ "xx" ]没法获取值?