Dear Ranchers:
I found one issue when i do the mock exam from
http://j2eeworld.weebly.com public class MyServlet extends HttpServlet {
private int x = 0;
public MyServlet (int x) {
this.x = x;
}
public void doGet (HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
x++;
PrintWriter out = response.getWriter();
out.println(x);
}
}
What will be the output (assume all imports are done correctly), when invoking MyServlet ?
A.Compiler error
B.Runtime Exception
C.Prints 1 in browser window.
D.Prints the value of x in browser window , depending up on the value used to create the
servlet.
The answer is B,but why?Could you give me some hint?
And another issue is if i override doPost,but not doGet in the servlet,and in my
jsp,I use the method="POST",are there some problem or not ?
Thanks anyway.