请问:getRequestDispatcher如何把参数也发送给下一个页面?
具体是这样的,当程序捕获到异常时,就转跳,同时要带错误信息tipMsg。我现在的代码是这样的,但是在businessAnalysis.jsp里用String tipMsg = request.getParameter( "tipMsg ");得到的却是null,不知道咋回事。
代码如下:
try{
tmp = startDate.split( "- ");
st = tmp[0]+ "/ "+tmp[1]+ "/ "+tmp[2] + " " + startHour + ": "+ startMin + ": "+ "00 ";
tmp = endDate.split( "- ");
et = tmp[0]+ "/ "+tmp[1]+ "/ "+tmp[2] + " " + endHour + ": "+ endMin + ": "+ "00 ";
}catch(Exception e){
tipMsg = "Error Date Format! ";
//System.exit(1); will close the server!!!
request.setAttribute( "searchDay ",startDate);
request.setAttribute( "tipMsg ",tipMsg);
//response.setAttribute( "tipMsg ",tipMsg);
request.getRequestDispatcher( "businessAnalysis.jsp ").forward(request, response);
//response.sendRedirect( "businessAnalysis.jsp?searchDay= "+startDate+ "&tipMsg= "+tipMsg);
}
关于这种动态的(根据判定条件决定如何转跳),带变量的页面转发,还有啥更好的办法么?为啥上面的代码不能把tipMsg传过去呢?
谢谢!
------解决方案--------------------把
String tipMsg = request.getParameter( "tipMsg ");
改成
String tipMsg = request.getAttribute( "tipMsg ");
试试
------解决方案--------------------request.getAttribute( "name ");
要不改成request.getRequestDispatcher( "businessAnalysis.jsp?tipmsg= "+tipmsg).forward(request, response);