标签:Insert title request here 地址 jsp response 页面
1.主页面,index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <% //转发地址不变,重定向地址改变 session.setAttribute("key", "Session"); %> <a href="request.jsp?id=6&name=admin">请求</a> <a href="response.jsp?id=10&name=root">响应</a> <br> <!-- 获取session id --> <%=session.getId() %> </body> </html>
2.request.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <% String id=request.getParameter("id"); String name=request.getParameter("name"); out.println(id+"==="+name); System.out.print("request执行了"); System.out.println("key"); //请求转发,前后页面共享一个request,RequestDispatcher.forward()是在服务器端运行; request.getRequestDispatcher("hello.jsp").forward(request, response); %> <br/> <!-- 获取session id --> <%=session.getId() %> </body> </html>
3.response.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <% String id=request.getParameter("id"); String name=request.getParameter("name"); System.out.println(id+"==="+name); System.out.println("key"); //重定向,前后页面不是一个request response.sendRedirect("hello.jsp"); %> <br/> <!-- 获取session id --> <%=session.getId() %> </body> </html>
4.欢迎页面,hello.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <h1>这是欢迎页面</h1> <% String id=request.getParameter("id"); String name=request.getParameter("name"); out.println("key"); out.println(id+"==="+name); %> <br/> <!-- 获取session id --> <%=session.getId() %> </body> </html>
标签:Insert,title,request,here,地址,jsp,response,页面 来源: https://www.cnblogs.com/jiangaihu/p/10949338.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。