在wicket中使用真实HTTP错误代码
我需要回复一个错误代码。当我使用AbortWithHttpStatusException时,我的响应如下:在wicket中使用真实HTTP错误代码,wicket,portlet,Wicket,Portlet,我需要回复一个错误代码。当我使用AbortWithHttpStatusException时,我的响应如下: HTTP/1.1 200 OK Server: Apache-Coyote/1.1 portlet.http-status-code: 507 Content-Type: text/html;charset=UTF-8 Content-Length: 0 Date: Tue, 10 Jan 2012 09:49:52 GMT 浏览器(至少firefox)会将其解释为200 OK,这似乎还
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
portlet.http-status-code: 507
Content-Type: text/html;charset=UTF-8
Content-Length: 0
Date: Tue, 10 Jan 2012 09:49:52 GMT
浏览器(至少firefox)会将其解释为200 OK,这似乎还可以,因为一开始就有HTTP/1.1 200 OK
。如何强制wicket返回其他http代码
我正在使用wicket 1.4.18我需要在wicket功能中使用相同的自定义HTTP状态代码(例如404未找到)(不使用portlet)和
configureResponse()
完美地工作:
package org.soluvas.web.bootstrap;
import org.apache.wicket.request.http.WebResponse;
/**
* @author atang
*
*/
public class PageNotFound extends BootstrapPage {
private static final long serialVersionUID = 1L;
public PageNotFound() {
super();
// add(new Page404());
}
@Override
protected void configureResponse(WebResponse response) {
super.configureResponse(response);
response.setStatus(404);
}
}
摘自项目。我需要同样的自定义Wicket中的HTTP状态代码(例如404未找到)功能(不使用portlet)和
configureResponse()
工作得很好:
package org.soluvas.web.bootstrap;
import org.apache.wicket.request.http.WebResponse;
/**
* @author atang
*
*/
public class PageNotFound extends BootstrapPage {
private static final long serialVersionUID = 1L;
public PageNotFound() {
super();
// add(new Page404());
}
@Override
protected void configureResponse(WebResponse response) {
super.configureResponse(response);
response.setStatus(404);
}
}
取自项目。是否
中止HttpStatusException
获取int
参数?@jbrookov是的,它是。我已经将它设置为507,这导致了portlet.http-status-code:507
部分,但这不是我想要实现的在portlet容器中使用它(portlet.http-status-code属性看起来像PortletResponse
特例)?@CedricGatay是的,我使用liferay作为容器。现在我已经添加了httpResponse.setStatus(statusCode)代码>在WicketResponseState中,它似乎工作得很好,但我不太喜欢我必须重写wicket类的事实…@AdamPierzchała问题是假定是portlet容器处理您的状态代码,您不应该绕过它。是否中止HttpStatusException
接受int
参数?@jbrookov是的,它接受。我已经将它设置为507,这导致了portlet.http-status-code:507
部分,但这不是我想要实现的在portlet容器中使用它(portlet.http-status-code
属性看起来像PortletResponse
特例)?@CedricGatay是的,我使用liferay作为容器。现在我已经添加了httpResponse.setStatus(statusCode)代码>在WicketResponseState中,它似乎工作得很好,但我不太喜欢我必须重写wicket类的事实…@AdamPierzchała问题是假设是portlet容器处理您的状态代码,您不应该绕过它谢谢您的输入,但是我记得问题是因为它是portlet。不管怎样,我不再参与这个项目了,所以我不能尝试它。谢谢你的输入,但是我记得问题是因为它是portlet。不管怎样,我不再参与这个项目了,所以我不能尝试。