jsp随记 2019.10.13---请求转发和重定向

更新(2019.12.03):

		两个挺蠢的语句,记录下吧,以后回顾
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
response.setContentType("text/html; charset=UTF-8");
PrintWriter out = response.getWriter();
		
String username = request.getParameter("username") ;

		
out.print("<script>alert('发送成功,请按提示操作。。') ;window.location='index.jsp'</script>");
response.sendRedirect("login1?id="+per.getUserid()+"&psd="+per.getPsd()+"") ;



1.request请求转发

  1. request跳转页面同时传值
String name = "haiyou1";
request.setAttribute("name", name);
request.getRequestDispatcher("/WEB-INF/new1.jsp").forward(request,response);
  1. request跳转页面后获取值
String name = request.getAttribute("name");

2.response重定向

response.sendRedirect("success.jsp") ;

在这里插入图片描述

发布了25 篇原创文章 · 获赞 5 · 访问量 1422

猜你喜欢

转载自blog.csdn.net/weixin_42245375/article/details/102534057