如何通过Struts返回401错误响应?

问题描述 投票:-1回答:1

我有一个返回类型ActionForward的方法,并且需要在某些情况下返回401响应。如何/我可以从这种方法返回什么来给出所需的结果?

public ActionForward doExecute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {

    ...

    if (some sort of error situation){
        // need to return a 401 here
    }

    ...
}
java struts
1个回答
1
投票
response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
© www.soinside.com 2019 - 2024. All rights reserved.