jsp使用url传值servlet接收为null怎么解决.

location.href="SelTaskInformationServlet?currentPage="+currentPage+"&pageSize="+pageSize 其中currentPage和pageSize是有值的,为:SelTaskInformationServlet?currentPage=1&pageSize=5 Servlet中获取的代码为: String tempCp = request.getParameter("currentPage"); String tempPs = request.getParameter("pageSize"); 然后tempCp和tempPs 为null,请问大神们这是为什么?

后台获取参数的代码是没错的,你唯一要确定是否有值。使用
String reqUrl = request.getRequestURL().toString(); 获得它的路径,然后打印出来,确认你的两个参数有没有传到后台
温馨提示:答案为网友推荐,仅供参考
第1个回答  2015-08-04
解决方法:
(1)在form表单传值:
在form表单里加上<input type="hidden" name="id" value="<%=bi.getId() %>"/>,在servlet中用request.getParameter取值。
(2)使用session会话机制:
在jsp页面设置session: session.setAttribute("id", bi.getId()) ,在servlet中取值:String id = (String)request.getSession().getAttribute("id") 。
(3)URL传值:
在form表单提交URL中传递参数:<form action="update.do?id=<%=bi.getId() %>" method="post">,servlet用request.getParameter取值。本回答被网友采纳
第2个回答  2013-09-29
你是在services方法中吗?还是在doget方法中?
第3个回答  2013-09-29
你的web.xml中怎么配置的,应该有关吧。。。