試試這個:
// check if request needs to be sent back
if (!isValidRequest()) {
// get the current execution context
Execution exec = Executions.getCurrent();
// retrieve HTTP request, response objects
HttpServletRequest request = (HttpServletRequest) exec.getNativeRequest();
HttpServletResponse response = (HttpServletResponse) exec.getNativeResponse();
// get the referring URL from HTTP header
String referrer = request.getHeader("Referer");
/* don't need to use this unless doing a forward (server-side)
if (referrer != null) {
URL ref = new URL(referrer);
referrer = ref.getPath().substring(request.getContextPath().length());
} else {
referrer = "/index.jsp"; // home page
}
*/
// HTTP 301 redirect (client-side); encoding ensures URL rewriting if required
response.sendRedirect(response.encodeRedirectURL(referrer));
exec.setVoided(true); // no need to create UI; about to redirect
}
你能解釋這裏發生了什麼?謝謝。 –
@SeanConnolly請檢查代碼註釋。 –