在jsp中使用request.setAttribute()为何在跳转到Action后无法提出

jsp是服务端的,你的request.setAttribute操作在传到客户端浏览器前已经执行了,这样的话重新提交或者跳转时会重新生成新的request生命周期,原先设置的attribute已经被冲掉了

public String kaoshilist4() { HttpServletRequest request = ServletActionContext.getRequest(); String truename = request.getParameter("truename"); String username = request.getParameter("username"); StringBuffer sb = new StringBuffer(); sb.append(" where "); StringBuffer sb2 = new StringBuffer(); sb2.append(" where "); if(username!=null&&!"".equals(username)){ sb.append(" user.username like '%"+username+"%'"); sb.append(" and "); sb2.append(" user.username like '%"+username+"%'"); sb2.append(" and "); request.setAttribute("username", username); } if(truename!=null&&!"".equals(truename)){ sb.append(" user.truename like '%"+truename+"%'"); sb.append(" and "); sb2.append(" user.truename like '%"+truename+"%'"); sb2.append(" and "); request.setAttribute("truename", truename); } sb.append(" 1=1 order by id desc"); String where = sb.toString(); sb2.append(" 1=1 "); String where2 = sb2.toString(); int currentpage = 1; int pagesize = 20; if (request.getParameter("pageNum") != null) { currentpage = Integer.parseInt(request.getParameter("pageNum")); pagesize = Integer.parseInt(request.getParameter("numPerPage")); } int total = kaoshiDao.selectBeanCount(where2); request.setAttribute("list", kaoshiDao.selectBeanList((currentpage - 1)* pagesize, pagesize, where)); request.setAttribute("totalCount", total); request.setAttribute("ps", pagesize); request.setAttribute("pn", currentpage); request.setAttribute("url", "method!kaoshilist4"); this.setUrl("kaoshi/kaoshilist4.jsp"); return SUCCESS; }解释此代码
06-10
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值