为什么response.setHeader和response.addHeader()不起作用?

headstream 2002-04-17 03:55:40
在servlet中是这样写的:

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public class sv1 extends HttpServlet
{
private static final String CONTENT_TYPE = "text/html; charset=GBK";
/**Initialize global variables*/
public void init() throws ServletException
{
}
/**Process the HTTP Post request*/
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
response.addHeader( "aaa", "abcde" );
response.sendRedirect( "http://localhost:7001/cu.jsp" );
}
/**Clean up resources*/
public void destroy()
{
}
}
在cu.jsp中显示请求头中没有我加入的aaa。
...全文
2123 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
dylanwolf 2002-04-22
  • 打赏
  • 举报
回复
我觉得你调用 response.sendRedirect()后,客户端直接去连接 cu.jsp,并不会把你的 Header给加进去。

headstream 2002-04-22
  • 打赏
  • 举报
回复
up一下

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧