0
我寫了一個簡單的計數器servlet應用程序來顯示訪問頁面的用戶數量。我想在jsp頁面中顯示這個結果。但我該怎麼做呢?下面是我的代碼...如何在jsp頁面顯示servlet結果?
public class ServerClass extends HttpServlet {
int counter = 0;
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
int local_count;
synchronized(this) {
local_count = ++counter;
}
out.println("Since loading, this servlet has been accessed " +
local_count + " times.");
out.close();
}
}
感謝戴夫..但它顯示計數變量的空值。我檢查了web.xml。不知道該怎麼辦.. Iam novel to servlet .. – Rosh
@Rosh現在你正在使用'processRequest',你應該爲'GET'請求使用'doGet'。如果它在實現'doGet'後仍然顯示'null',則需要發佈更多細節。 –
謝謝戴夫..它現在的作品.. :) – Rosh