2011-12-10 63 views
1

隨着下面的頁面,我期待看到我的消息This page requires...但我看到的只是一個空白頁面(沒有錯誤)。Servlet顯示無輸出

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

明顯的問題:System.out寫入本地控制檯,而不是要顯示的網頁。您要發送給請求客戶端的所有內容都必須寫入HttpServletResponse對象。