2016-02-06 156 views
0

我正在使用AppEngine服務器來回答我的應用程序的HTTP-Get請求,但請求始終返回index.html的HTML。HTTP-Get請求返回HTML代碼(Google AppEngine)

這是我的doGet法:

@Override 
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { 
    String name = req.getParameter("name"); 
    String score = req.getParameter("score"); 
    if(score==null && name!=null){ 
     resp.getWriter().println(name); 
    } 
    else if(name!=null && score!=null){ 
     int p = Integer.parseInt(score); 
     addHighscore(name, p); 
    } 
    else{ 
     resp.getWriter().println("error"); 
    } 
} 

所以,如果我輸入網址http://high-1212.appspot.com/?name=test到我的瀏覽器,我希望它返回名稱參數的值,但它只返回的網頁。所以我的應用程序不會顯示參數的值,而是顯示HTML代碼。出於這個原因,我想,這是因爲doGet-Method。但我不明白,什麼是錯的。

+1

對這些術語進行網絡搜索:web.xml,servlet-mapping – konqi

回答

0

默認情況下,當您訪問網站時會加載主頁。如果要顯示發送的數據,則必須在響應頁面中執行。

相關問題