Jsf 在执行sendRedirect时使用Post

Jsf 在执行sendRedirect时使用Post,jsf,redirect,Jsf,Redirect,我有一个要求,jsf页面需要从用户浏览器中的自定义瘦客户端启动(瘦客户端执行http post)。由于jsf页面可能会被多次调用,因此我使用jsp重定向到带有url上参数的jsf页面。在jsp中,我执行会话失效。jsp代码如下所示: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <%@page session="true

我有一个要求,jsf页面需要从用户浏览器中的自定义瘦客户端启动(瘦客户端执行http post)。由于jsf页面可能会被多次调用,因此我使用jsp重定向到带有url上参数的jsf页面。在jsp中,我执行会话失效。jsp代码如下所示:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@page session="true" %>

<%
response.setHeader("Cache-Control", "no-cache");
response.setHeader("Pragma", "no-cache");
session.invalidate();

String outcome = request.getParameter("outcome");


String queryString = "outcome=" + outcome ;

response.sendRedirect("./faces/MyPage.jspx?"  + queryString);


%>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"></meta>
    <title>title here</title>
  </head>
  <body></body>
</html>
这样,即使在多次自动提交下拉列表之后,我也可以获得参数

我的问题是我不能让参数显示在浏览器地址栏上。我需要一种方法,以便可以将参数传递到jsp页面。我无法从瘦客户机直接发布到jsp,因为每次客户机启动用户浏览器时,我都需要jsf页面有一个新的会话。这是由于上面关于如何在jsf页面中使用params的代码片段造成的

在执行sendRedirect时是否有任何方法可以使用post,这样我就不必在url上传递参数?我不能使用forward,因为当自动提交在jsf页面上触发时,它会导致浏览器刷新jsp页面


有没有更好的方法来处理jsf页面本身,这样我就不必在连续的autoSubmit事件之间的会话上存储参数了?

因为您使会话无效,不,您不能

唯一的办法是将其放入会话范围。顺便问一下,为什么您在第一次请求时就使会话无效?这真的毫无意义


与您的实际问题无关,在scriptlet中执行
sendRedirect()
,而不是在
过滤器中执行
,并且在同一个JSP页面中使用大量HTML,这是一个大麻烦。不要在JSP文件中编写原始Java代码,您不希望这样。Java代码属于Java类。仅在JSP中使用taglibs/EL。

否。因为sendRedirect将web浏览器/客户端a 302与新位置一起发送,并且根据以下内容,无论原始请求是什么,它通常都是GET

根据HTTP/1.1 RFC 2616:

也许谨慎地使用ajax可以让你有所收获

更新:然后,正如user:所指出的,您可以通过手动设置标题进行重定向,如下所示:

response.setStatus(307);
response.setHeader("Location", "http://google.com");

对于那些将问题解释为“我可以重定向POST请求吗?”,那么答案将是“是的,你可以,使用307重定向。”同意。但据我所知,无法使用JSP sendRedirect()方法执行307。不,它默认为302。但是,您可以自己设置响应状态和标题。另见
If the 302 status code is received in response to a request other
than GET or HEAD, **the user agent MUST NOT automatically redirect the
request unless it can be confirmed by the user**, since this might
change the conditions under which the request was issued.

Note: RFC 1945 and RFC 2068 specify that the client is not allowed
to change the method on the redirected request.  However, ***most
existing user agent implementations treat 302 as if it were a 303
response, performing a GET on the Location field-value regardless
of the original request method***. The status codes 303 and 307 have
been added for servers that wish to make unambiguously clear which
kind of reaction is expected of the client.
response.setStatus(307);
response.setHeader("Location", "http://google.com");