1、后台部分(a/登录,建一个LoginServlet类继承HttpServlet父类)
package com.iotek.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class LoginServlet extends HttpServlet{
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
ServletContext application = req.getServletContext();
Integer count = (Integer)application.getAttribute("count");
if(count==null){
application.setAttribute("count", 1);
}else{
application.setAttribute("count", count+1);
}
resp.sendRedirect("index.jsp");
}
}
<