网站开发的排期,电子商务网站建设精英,网站开发待遇,深圳广告设计公司深圳画册设计JSP属性范围#xff0c;通过以下几个测试代码来学习request属性的范围 测试一(JSP动态指令方式传参)#xff1a;
测试内容#xff1a;
jsp:param .../添加参数,通过jsp:forward page...来实现服务器端跳转,以此来测试request属性的范围#…JSP属性范围通过以下几个测试代码来学习request属性的范围 测试一(JSP动态指令方式传参)
测试内容
jsp:param .../添加参数,通过jsp:forward page...来实现服务器端跳转,以此来测试request属性的范围
页面RequestScopeDemo.jsp (添加info1参数) — 通过jsp:forward pageRequestScopeDemo_1.jsp跳转 ↓ 页面RequestScopeDemo_1.jsp (添加info2参数) — 通过jsp:forward pageRequestScopeDemo_2.jsp跳转 ↓ 页面RequestScopeDemo_2.jsp (request对象中取到了info1、info2两个参数的值)
CODE:
RequestScopeDemo.jsp : % page contentTypetext/html;charsetUTF-8 pageEncodingUTF-8%
html
headtitleRequest属性范围 - Page 1/title/head
bodyh1跳转前的页面page 1/h1%//想输入一个字符串“jsp:param ... ”不能直接输出必须通过转义输出String info1page 1 页面中添加jsp:param ... /的参数 !;request.setCharacterEncoding(utf-8);%jsp:forward pageRequestScopeDemo_1.jspjsp:param nameinfo1 value%info1% //jsp:forward
/body
/html
RequestScopeDemo1.jsp : % page contentTypetext/html;charsetUTF-8 pageEncodingUTF-8%
html
headtitleRequest属性范围 - page2/title/head
bodyh1跳转中页面page 2/h1%String info2page 2 页面中添加jsp:param ... /的参数 !; %info参数%request.getParameter(info2)%br/jsp:forward pageRequestScopeDemo_2.jspjsp:param nameinfo2 value%info2% //jsp:forward
/body
/html
RequestScopeDemo2.jsp : % page contentTypetext/html;charsetUTF-8 pageEncodingUTF-8%
html
headtitleRequest属性范围 - page3/title/head
bodyh1跳转到的页面page 3/h1%/*request对象的源头设置了编码所以这里就不需要设置啦*///request.setCharacterEncoding(utf-8); %h2Page1页面中传递过来的info1参数%request.getParameter(info1)%/h2br/h2Page2页面中传递过来的info2参数%request.getParameter(info2)%/h2br/h2request.getCharacterEncoding()的值%request.getCharacterEncoding()%/h2
/body
/html 测试结果 测试二request.setAttribute()封装属性方式传参 测试内容
request.setAttribute()方法封装参数通过jsp:forward page...来实现服务器端跳转以此来测试request属性的范围
页面RequestScopeDemo_t.jsp (添加info1参数) — 通过jsp:forward pageRequestScopeDemo_t1.jsp跳转 ↓ 页面RequestScopeDemo_t1.jsp (添加info2参数) — 通过jsp:forward pageRequestScopeDemo_t2.jsp跳转 ↓ 页面RequestScopeDemo_t1.jsp (request对象中取到了info1、info2两个参数的值)
CODE: RequestScopeDemo_t.jsp : % page contentTypetext/html;charsetUTF-8 pageEncodingUTF-8%
html
headtitleRequest属性范围 - Page 1/title/head
bodyh1跳转前的页面page 1/h1%request.setCharacterEncoding(utf-8);request.setAttribute(info1,Page1中添加setAttribute的参数);%jsp:forward pageRequestScopeDemo_t1.jsp /
/body
/html
RequestScopeDemo_t1.jsp : % page contentTypetext/html;charsetUTF-8 pageEncodingUTF-8%
html
headtitleRequest属性范围 - page2/title/head
bodyh1跳转中页面page 2/h1%request.setAttribute(info2,Page2中添加setAttribute的参数);%跳转中的页面info1参数%request.getAttribute(info1)%br/jsp:forward pageRequestScopeDemo_t2.jsp /
/body
/html
RequestScopeDemo_t2.jsp : % page contentTypetext/html;charsetUTF-8 pageEncodingUTF-8%
html
headtitleRequest属性范围 - page3/title/head
bodyh1跳转到的页面page 3/h1h2第一个页面info1参数%request.getAttribute(info1)%/h2br/h2第二个页面info2参数%request.getAttribute(info2)%/h2br/h2request.getCharacterEncoding()的值%request.getCharacterEncoding()%/h2
/body
/html 测试结果 测试三URL地址方式传参
测试内容
URL地址方式添加参数通过超链接a href.. ..来实现服客户端跳转以此来测试request属性的范围
页面RequestScopeDemo_1.jsp 页中通过a hrefRequestScopeDemo_2.jsp?info1Page1页面的参数链接到下一个页面/a跳转 ↓ 页面RequestScopeDemo_2.jsp 页中通过a hrefRequestScopeDemo_3.jsp?info2Page1页面的参数链接到下一个页面/a跳转 ↓ 页面RequestScopeDemo_2.jsp(request对象中取到了info2的参数值)
CODE:
RequestScopeDemo_1.jsp : % page contentTypetext/html;charsetUTF-8 pageEncodingUTF-8%
html
headtitleQequest属性范围 - Page 1/title/head
bodyh1跳转前的页面page 1/h1%request.setCharacterEncoding(utf-8);%a hrefRequestScopeDemo_2.jsp?info1Page1页面的参数链接到下一个页面/a
/body
/html RequestScopeDemo_2.jsp : % page contentTypetext/html;charsetUTF-8 pageEncodingUTF-8%
html
headtitleRequest属性范围 - page2/title/head
bodyh1跳转中页面page 2/h1%request.setAttribute(info2,Page2中的参数);%跳转中的页面info1参数%request.getParameter(info1)%br/a hrefRequestScopeDemo_3.jsp?info2Page2页面的参数链接到下一个页面/a
/body
/html RequestScopeDemo_3.jsp : % page contentTypetext/html;charsetUTF-8 pageEncodingUTF-8%
html
headtitleRequest属性范围 - page3/title/head
bodyh1跳转到的页面page 3/h1h2第一个页面info1参数%request.getParameter(info1)%/h2br/h2第二个页面info2参数%request.getParameter(info2)%/h2br/h2request.getCharacterEncoding()的值%request.getCharacterEncoding()%/h2
/body
/html 测试结果 总结request属性在服务器端跳转时request相当于是一个消息信息在各个页面中传递各个页面是共享同一个request对象。