智慧社区管理平台的定义是什么?

servlet下怎样使用session?(重点是向session传值)
servlet下怎样使用session?(重点是向session传值)
09-10-11 &
空值异常!但是最好还是先检查下你创建SERVLET时随着生成的WEB-XML文件中,那一对SERVLET标签是否对应上,之后你就可以分为下面的几种情况查找病源了.引起的原因有:1.在超链接传值的时候,也须你传的是空值,这个比较好找!用几个System.out.println();就能解决!2.你传完值,有可能在SERVLET里面没有接值,或者压根你就没有向这个SERVLET里面传值3.往往出现的错误是你传值的NAME名与接值时的NAME名对不上,所以接不着值我的 解决办法只局限MVC开发模式,如果你用的是hibernate与struts整合的开发模式,你得用上面那位的解决方式!
请登录后再发表评论!Session传值的问题 - ITeye问答
我登陆系统后,系统页面通过session获取用户的时候就出现下面的错误
java.lang.illegalstateexception cannot create a session after the response has been committed
这是为什么啊,我的action的代码:
&&&&&&&&&&&&&&& session.setAttribute("userInfoVO", userInfoVO);
&&&& return mapping.findForward("success");
&&&&&&&
&&&&&&&&&&& 前台页面的取值:
&&&&&&&&&&&&&&& &logic:empty name="userInfoVO"&
&a href="${ctx}/" target="_top"&--- 请登录!---&/a&
&&& &/logic:empty&
&&& &logic:notEmpty name="userInfoVO"&
&&&&&&&&&&&&&&&&&&&&& ${sessionScope.userInfoVO.username}
&&&&&&&&&&&&& &/logic:notEmpty&
我找了好久了,没发现哪里有问题,我直接sessionScope.userInfoVO.username这样写,不用标签,也不行,
不知道错在哪里了,大家帮忙解决哈,搞了很久了问题补充:问题解决了,是jsp页面有response输出流,我换了页面就没事了,呵呵,谢谢大家啦
shift8说的对,你是不是把response关闭了?
& &logic:notEmpty name="userInfoVO"&
&&&&&&&&&&&&&&&&&&&&& ${sessionScope.userInfoVO.username}
&&&&&&&&&&&&& &/logic:notEmpty&
这一段代码改成:
& &logic:notEmpty name="userInfoVO" scope="session"&
&&&&&&&&&&&&&&&&&&&&& ${userInfoVO.username}
&&&&&&&&&&&&& &/logic:notEmpty&
java.lang.illegalstateexception cannot create a session after the response has been committed
这个问题就是响应已经关闭结束了,你还在用session
有个类似的问题
/topic/106398
把你代码多粘一些出来,配置之类
有时候在操作Session时,系统会抛出如下异常
java.lang.IllegalStateException: Cannot create a session after the response has been committed
之所以会出现此类问题是因为我们在Response输出响应后才创建Session的。
因为那时候服务器已经将数据发送到客户端了,即:就无法发送Session ID 了.
mapping.findForward("success");
在这之后是不是进行了页面重定向,而不是转发哦。
已解决问题
未解决问题在servlet中,通过getparameter与setparameter来实现后端与前端jsp页面的数据交互,那么在struts中,也有几种方式来操作request,session实现后端与前端的交互。
法一(推荐):使用RequestAware,SessionAware接口
1.实现这两个接口
public class NewsAction extends ActionSupport implements RequestAware,SessionAware {}
2.定义两个成员变量
private Map&String,Object&
private Map&String,Object&
3.重写接口中的方法。
public void setRequest(Map&String, Object& arg0) {
this.request = arg0;
public void setSession(Map&String, Object& arg0) {
// TODO Auto-generated method stub
this.session = arg0;
4.使用session.put(),session.get(),request.put(),request.get()
request.put(key, value);
request.get(key);
session.put(key, value);
session.get(key);
法二:使用ActionContext.getContext().get("request");
Map&String,Object& request = (Map&String,Object&)ActionContext.getContext().get("request");
request.put(key, value);
request.get(key);
Map&String,Object& session = ActionContext.getContext().getSession();
session.put(key, value);
session.get(key);
法三:使用ServletActionContext.getRequest()
HttpServletRequest request = ServletActionContext.getRequest();
request.setAttribute(arg0, arg1);
request.getAttribute(arg0)
HttpServletRequest req = ServletActionContext.getRequest();
HttpSession session = req.getSession();
session.setAttribute(arg0, arg1);
session.getAttribute(arg0);
阅读(...) 评论()session传值问题
几个页面,AddSurve.servlet-&prepare.jsp-&AddQuestion.jsp-&AddQuestion.servlet-&ShowQueByPage.jsp
我在AddSurve.servlet设置一个session.setAttitude(),
HttpSession Session=request.getSession(true);
Session.setAttribute(&sID&, survey.getS_id());
为什么在ShowQueByPage.jsp里使用是为空呢?如下:
session.getAttribute(&SID&);或者
Enumeration e = session.getAttributeNames();
while (e.hasMoreElements())
& & String name = e.nextElement().toString();
& & Object value = request.getAttribute(name);
& & System.out.println(&&b&& + name + &&/b& = & + value + &&br&\n&);
第一个是因为变量名不一致导致的 一个是sID 一个是SID导致的 变量名是区分大小导致的
第二个是因为你从session中取到名字(session.getAttributeNames())后,又从request中取值导致的(&request.getAttribute(name) ),request和session不是一会事哦
引用来自“享开发”的答案 第一个是因为变量名不一致导致的 一个是sID 一个是SID导致的 变量名是区分大小导致的
第二个是因为你从session中取到名字(session.getAttributeNames())后,又从request中取值导致的(&request.getAttribute(name) ),request和session不是一会事哦
谢谢你回答!其实我的程序里没写错,在这里写错了,都是sID。恩!我还想请教一个问题:想要用hibernate存储数据,三个表,Survey(s_id)、Questions(q_id)和AnswerSheer(survey_id,questions_id),Survey和Questions是多对多的关系,AnswerSheet是中间表,当我存储一个Survey和一个Questions之后,想吧它们存进中间表并关联起来,怎么办?还有,想查询中间表的信息String &hql &= & &from AnswerSheet as a where a.survey_id=&+sID ;出错:could not resolve property: Survey of: com.bean.AnswerSheet [from com.bean.AnswerSheet as a where a.Survey.s_id=24]
--- 共有 1 条评论 ---
又写错了!could not resolve property: survey_id of: com.bean.AnswerSheet [from com.bean.AnswerSheet as a where a.survey_id=24]
上边写错的我也试了,啊好像也不对?

我要回帖

更多关于 智慧社区服务平台 的文章

 

随机推荐