J2EE Spring MVC:如何在Interceptor或Filter上更改主体内容?

时间:2015-07-02 13:05:30

标签: java spring spring-mvc

我正在使用Spring MVC构建带加密的后端服务, 我需要在Internet上加密传输所有数据(客户端到服务器和S2C)。

如何在Java Interceptor或Filter上更改正文内容?

public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView mav) throws Exception {
    // I try to change the response body on here.
    // But it seemed can't , I can't read the body out and set new encrypted body back.
}

1 个答案:

答案 0 :(得分:0)

您可以从modalAndAttribute的客户端 - 服务器拦截任何您想要的内容,这里有一个关于我如何拦截先前呈现给视图的实体的示例,称之为候选资格

@ModelAttribute("candidacy")
public Candidacy bindAbstractOrganizationOnCandidacy(final HttpServletRequest request) throws CandidacyException {
    String discriminator = request.getParameter(CANDIDACY_TYPE);
    Candidacy candidacy = null;
    if (discriminator != null) {
        candidacy = new Candidacy();
        candidacy.setCompany(AbstractCandidacyOrganizationBuilder.buildByDiscriminator(discriminator));
    }
    return candidacy;
}

这就是你需要的吗?