request.setAttribute("url", url);
request.getRequestDispatcher("test2.jsp").forward(request,reponse);
then test2.jsp
<%@ page language="java" pageEncoding="UTF-8"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
${url}
</body>
</html>
質問
guys, I want to pass values from one html page to another. In test1.html, submit the value to Serlvet. In servlet got the value, and dispatcher request to test2.html. like this:
request.setAttribute("url", url);
request.getRequestDispatcher("test2.html").forward(request,reponse);
So, how can i get the "url" value in test2.html?. need help, thx!
解決
request.setAttribute("url", url);
request.getRequestDispatcher("test2.jsp").forward(request,reponse);
then test2.jsp
<%@ page language="java" pageEncoding="UTF-8"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
${url}
</body>
</html>
他のヒント
As the forward is entirely server-side, the attribute should still be present in the request. So from test2.html (actually you should make this a JSP page, test2.jsp), you can do the following:
<%
String url = (String)request.getAttribute("url");
%>
And if you wish to display it:
<html> ...
The URL is: <%=url%>
</html>