⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 931686.xml

📁 论坛精华帖子
💻 XML
字号:
<?xml version='1.0' encoding='GB2312'?>
<?xml-stylesheet type='text/xsl' href='../csdn.xsl'?>
<Topic>
<Issue>
<PostUserNickName>joe</PostUserNickName>
<rank>二级(初级)</rank>
<ranknum>user2</ranknum>
<credit>95</credit>
<TopicId>931686</TopicId>
<TopicName>谁帮帮我吧</TopicName>
<PostUserId>186137</PostUserId>
<PostUserName>joe2002</PostUserName>
<RoomName>JSP</RoomName>
<ReplyNum>6</ReplyNum>
<PostDateTime>2002-8-11 9:52:01</PostDateTime>
<Point>100</Point>
<ReadNum>0</ReadNum>
<RoomId>28</RoomId>
<EndState>2</EndState>
<Content>能告诉我
session.setAttribute();
request.setAttribute();
他们存入的值的有效范围?
</Content>
</Issue>
<Replys>
<Reply>
<PostUserNickName>摇滚java</PostUserNickName>
<rank>两星(中级)</rank>
<ranknum>star2</ranknum>
<credit>100</credit>
<ReplyID>6005212</ReplyID>
<TopicID>931686</TopicID>
<PostUserId>34087</PostUserId>
<PostUserName>gdsean</PostUserName>
<Point>100</Point>
<Content>1.session.setAttribute();

If&#32;the&#32;object&#32;being&#32;stored&#32;in&#32;the&#32;session&#32;object&#32;implements&#32;HttpSessionBindingListener,&#32;then&#32;the&#32;container&#32;calls&#32;HttpSessionBindingListener.valueBound.&#32;

If&#32;you&#32;have&#32;an&#32;invalidated&#32;session&#32;then&#32;this&#32;function&#32;throws&#32;an&#32;IllegalStateException.&#32;

2.request.setAttribute();
跟session的方法不同,你只能使用在一个request里面
要想使用里面保存的对象,只能在include或者forward的页面使用


RequestDispatcher&#32;dispatcher&#32;=&#32;getServletContext().getRequestDispatcher(url);

request.setAttribute("name",&#32;"test");

dispatcher.forward(request,&#32;response);
//那么第二个页面也能使用request里面的对象

要是该request不是从dispatcher传递过去的
里面不会包含先前设置的对象





</Content>
<PostDateTime>2002-8-11 10:17:22</PostDateTime>
</Reply>
<Reply>
<PostUserNickName>joe</PostUserNickName>
<rank>二级(初级)</rank>
<ranknum>user2</ranknum>
<credit>95</credit>
<ReplyID>6005394</ReplyID>
<TopicID>931686</TopicID>
<PostUserId>186137</PostUserId>
<PostUserName>joe2002</PostUserName>
<Point>0</Point>
<Content>我是用的dispatcher传递request。
我想问的是
如果我要把login的user信息一直带到后面的话,是不是一直只用一个request,这样forward来forward去?</Content>
<PostDateTime>2002-8-11 10:33:16</PostDateTime>
</Reply>
<Reply>
<PostUserNickName>joe</PostUserNickName>
<rank>二级(初级)</rank>
<ranknum>user2</ranknum>
<credit>95</credit>
<ReplyID>6005478</ReplyID>
<TopicID>931686</TopicID>
<PostUserId>186137</PostUserId>
<PostUserName>joe2002</PostUserName>
<Point>0</Point>
<Content>另外我想问一下,
session和request到底有没有包含关系?
我看到request可以得到或者创建一个新的session,
如果我在jsp叶面不是用userbean方式来使用我的bean,而是在servlet中将bean实例存入request中,再dispatcher到页面,这样作对不对?
要是能这样做的话,再次提交jsp的时候,我刚才存在request中的bean实例会不会还在?还是说,每次submit之后都要生成一个新的request?
谢谢了。实在感激!</Content>
<PostDateTime>2002-8-11 10:41:18</PostDateTime>
</Reply>
<Reply>
<PostUserNickName>摇滚java</PostUserNickName>
<rank>两星(中级)</rank>
<ranknum>star2</ranknum>
<credit>100</credit>
<ReplyID>6012064</ReplyID>
<TopicID>931686</TopicID>
<PostUserId>34087</PostUserId>
<PostUserName>gdsean</PostUserName>
<Point>0</Point>
<Content>在servlet中将bean实例存入request中,再dispatcher到页面是对的
Http是一个无状态的连接,新的request不会保存上个request的数据,
唯有通过传递request对象的方法。
你的情况最好还是使用session吧

</Content>
<PostDateTime>2002-8-11 20:38:46</PostDateTime>
</Reply>
<Reply>
<PostUserNickName>joe</PostUserNickName>
<rank>二级(初级)</rank>
<ranknum>user2</ranknum>
<credit>95</credit>
<ReplyID>6012460</ReplyID>
<TopicID>931686</TopicID>
<PostUserId>186137</PostUserId>
<PostUserName>joe2002</PostUserName>
<Point>0</Point>
<Content>唯有通过传递request对象的方法。

这句话不太明白,
怎样传递呢?
比如在新的request要提交的时候,也就是每次submit()的时候,怎样把上次的request给传递到servlet中呢。还是在jsp的submit()之前,写....forward(request,response)吗?
</Content>
<PostDateTime>2002-8-11 21:09:48</PostDateTime>
</Reply>
<Reply>
<PostUserNickName>摇滚java</PostUserNickName>
<rank>两星(中级)</rank>
<ranknum>star2</ranknum>
<credit>100</credit>
<ReplyID>6014941</ReplyID>
<TopicID>931686</TopicID>
<PostUserId>34087</PostUserId>
<PostUserName>gdsean</PostUserName>
<Point>0</Point>
<Content>"唯有通过传递request对象的方法。"
就是只有通过RequestDispatcher将当前的
request传递到下一个页面</Content>
<PostDateTime>2002-8-12 12:45:28</PostDateTime>
</Reply>
</Replys>
</Topic>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -