请问requestDispatcher的forward方法如何传递参数。搜索了一下使用request.setAttribute()进行设置,好象不能进行传递。
代码如下:
1.jsp
<%@ page contentType="text/html; charset=GBK" %>
<html>
<head>
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312">
<title>测试</title>
</head>
<body>
<a href="2.jsp?flag=123">go page</a>
</body>
</html>2.jsp
<%
request.setAttribute("newflag","test");
request.getRequestDispatcher("3.jsp").forward(request,response);
%>3.jsp
<%@ page contentType="text/html; charset=GBK" %>
<%
String flag = request.getParameter("flag");
out.println("start<BR>");
out.println("flag:"+flag);
out.println("<BR>over flag<BR>");
String newflag = request.getParameter("newflag");
out.println("newflag:"+newflag);
out.println("<BR>over newflag");
%>
以上三个最简单的页面,在3.jsp页面上无法得到在2.jsp页面上设置的参数newflag的值,不知方法有误,还是本身就无法实现这类需求?
请多指点,谢谢!
代码如下:
1.jsp
<%@ page contentType="text/html; charset=GBK" %>
<html>
<head>
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312">
<title>测试</title>
</head>
<body>
<a href="2.jsp?flag=123">go page</a>
</body>
</html>2.jsp
<%
request.setAttribute("newflag","test");
request.getRequestDispatcher("3.jsp").forward(request,response);
%>3.jsp
<%@ page contentType="text/html; charset=GBK" %>
<%
String flag = request.getParameter("flag");
out.println("start<BR>");
out.println("flag:"+flag);
out.println("<BR>over flag<BR>");
String newflag = request.getParameter("newflag");
out.println("newflag:"+newflag);
out.println("<BR>over newflag");
%>
以上三个最简单的页面,在3.jsp页面上无法得到在2.jsp页面上设置的参数newflag的值,不知方法有误,还是本身就无法实现这类需求?
请多指点,谢谢!
return;
进行传递的