结果重定向不适用于jsp [英] Result redirection not working with jsp

查看:93
本文介绍了结果重定向不适用于jsp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在servlet中收到ping结果,正在尝试将其重定向到另一个jsp文件.

I'm getting a ping result in my servlet.I'm trying to redirect it to another jsp file.

用于输出的jsp文件已打开.但是其中没有任何显示.

the jsp file for output opens.But nothing shows in it.

这是我的servlet主代码

This is my servlet main code

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页面

This is my output.jsp page

<%@ 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中添加任何内容吗?

Do I need to add anything in output.jsp?

推荐答案

在您的servlet中:

In your servlet:

request.setAttribute("result", result);
request.getRequestDispatcher("/WEB-INF/Output.jsp").forward(request, response);

在您的JSP中:

<pre>The data from servlet: ${result}</pre>

这篇关于结果重定向不适用于jsp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆