如何在HTTP响应中设置标头?
2022-09-02 22:02:44
我有一个 servlet A,我在 HTTP 响应中设置了一个标头:
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String userName=request.getParameter("userName");
String newUrl = "http://somehost:port/ServletB";
response.addHeader("REMOTE_USER", userName);
response.sendRedirect(newUrl);
}
现在在 servlet B 中,我正在尝试获取在 servlet A 中设置的标头值:
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String userid = request.getHeader("REMOTE_USER");
}
但是在这里,userid的价值是 .请让我知道我在这里错过了什么。null