【发布时间】:2014-02-15 12:26:32
【问题描述】:
我在我的 servlet 中得到一个 ping 结果。我正在尝试将它重定向到另一个 jsp 文件。
用于输出的 jsp 文件打开。但其中没有显示任何内容。
这是我的servlet主要代码
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
String ip = request.getParameter("ip");
response.setContentType("text/html");
PrintWriter out = response.getWriter();
// out.println("The ip address is:"+ip+"\n");
String result = pingTest(ip);
out.println(result);
String redirect = "Output.jsp";
RequestDispatcher view = request.getRequestDispatcher(redirect);//Is it good approach to redirect request in ajax based servlet?
view.forward(request, response);
}
这是我的 output.jsp 页面
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Ping Check Result</title>
</head>
<body>
</body>
</html
是否需要在 output.jsp 中添加任何内容?
【问题讨论】:
-
好吧,您的 JSP 主体中没有任何内容。那么它为什么要显示任何东西呢?此外,您正在做的是转发(这很好),而不是重定向,这是完全不同的事情。