servlet的重定向问题(在线等,解决立即给分)

zzhangwa 2003-05-01 10:51:24
为什么我的servlet不能重定向到index.jsp
源码package oamclientweb.util;

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

public class DataInitView extends HttpServlet {
static final private String CONTENT_TYPE = "text/html; charset=GBK";
//Initialize global variables
public void init() throws ServletException {
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>DataInitView</title></head>");
out.println("<body>");
out.println("<p>The servlet has received a GET. This is the reply.</p>");
out.println("</body></html>");
out.close();
response.sendRedirect("index.jsp");
}
//Clean up resources
public void destroy() {
}
}
...全文
87 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
zzhangwa 2003-05-01
  • 打赏
  • 举报
回复
这个我试过了,是可以的,但是为什么加上了out.println()就不行呢?
我还有个问题就是
现在我要进行的逻辑操作(servlet)可能时间稍长,界面就是一直白屏的,我想显示一些提示性的语句如何实现呢?
biggie 2003-05-01
  • 打赏
  • 举报
回复
你都已经out.println
还怎么response呢!
wellsoon 2003-05-01
  • 打赏
  • 举报
回复
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
response.setHeader("Pragma","No-cache");//HTTP 1.1
response.setHeader("Cache-Control","no-cache");//HTTP 1.0
response.setHeader("Expires","0");//防止被proxy
request.setCharacterEncoding("GB2312");//设置编码
//直接重定向到登陆出错页面
response.sendRedirect("errorlogin.jsp");
}

把out.println()全部去掉。

81,122

社区成员

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

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