1
這裏的東西,重新注入POSTDATA重定向請求
爲了模仿Grails的方式做多次提交的一種形式,我實現了這個攔截器,這樣,當它遇到一個URL,例如:
/什麼-url/$ {controllerName}/index它重定向到/無論url/$ {controllerName}/$ {submitName}
我有兩個問題,首先它被重定向get方法,第二我不保留jsp中的原始表單的postData,任何人都有一個想法如何在重定向的請求中設置它?
這裏是攔截器類:
public class ControllerIndexInterceptor extends HandlerInterceptorAdapter {
private static String[] redirects = {"edit", "delete"};
/**
* {@inheritDoc}
*/
@Override
public boolean preHandle(HttpServletRequest request,
HttpServletResponse response, Object handler) throws Exception {
String param = null;
for (String redirect : redirects) {
if((param = request.getParameter(redirect)) != null){
response.sendRedirect(request.getContextPath()+request.getServletPath()+
transformURI(request.getPathInfo(), redirect, handler));
return false;
}
}
return true;
}
答:
public class ControllerIndexInterceptor extends HandlerInterceptorAdapter {
private static String[] redirects = {"edit", "delete"};
/**
* {@inheritDoc}
*/
@Override
public boolean preHandle(HttpServletRequest request,
HttpServletResponse response, Object handler) throws Exception {
String param = null;
for (String redirect : redirects) {
if((param = request.getParameter(redirect)) != null){
request.getRequestDispatcher(request.getServletPath()+
transformURI(request.getPathInfo(), redirect, handler)).forward(request,response);
return false;
}
}
return true;
}
謝謝,我不得不改變一點代碼,但請求調度員是答案。 – Gepsens