Servlet显示无输出

时间:2011-12-10 22:03:21

标签: java servlets java-ee-6

在下面的页面中,我希望看到我的消息This page requires...,但我看到的只是一个空白页面(没有错误)。

package guest;

import java.io.IOException;
import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(urlPatterns = {"/guestExport"})
public class GuestExportServlet extends HttpServlet {

    //Injected DAO EJB
    @EJB GuestDao guestDao;

    @Override
    protected void doGet(
        HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        System.out.println("This page requires a POST");
    }

    @Override
    protected void doPost(
        HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        System.out.println("This page is a POST");
    }
}

这里有任何明显的问题吗?

1 个答案:

答案 0 :(得分:1)

明显的问题:System.out写入本地控制台,而不是您要显示的网页。您要传递给请求客户端的所有内容都必须写入HttpServletResponse对象。