您的位置:首页 > 其它

servlet 中的转发和重定向传值

2017-11-23 00:00 127 查看
摘要: servlet 中的转发和重定向传值

转发
request.setAttribute("message",message);
//request.setAttribute("path",analyPath);
//转发传值:"/myImportDataServlet.do?path="+analyPath
request.getRequestDispatcher("/myImportDataServlet.do?path="+analyPath).forward(request, response);

//重定向传值
request.getSession().setAttribute("path", analyPath);
//重定向界面“importData” 项目请求配置path 路径
response.sendRedirect("/importData/myImportDataServlet.do");

另一个Servlet 获取值

//获取转发的值
String path=request.getParameter("path");

//获取重定向的值
String path=(String) request.getSession().getAttribute("path");
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息