Let’s say I have a web application on server using servlet without any frameworks. I’m little confused about how the classes are produced based on HttpRequest. For example I have this servlet
public class WelcomeServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title> A very simple servlet example</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>"+ (int)(Math.random()*5) +"</h1>");
out.println("</body>");
out.println("</html>");
out.close();
}
}
Questions:
-
if there are two/more clients access this servlet, Will they receive different instances of this class or only one class to be used by they two? will they get same number?
-
Is it good idea to use static class on servlet? for example on class that holds constant number/String or SQL query?
-
I store sensitive info on HttpSession, is it good?
Thanks.