Milestone 1: Screenshot of the Tomcat installed successfully
Milestone 2: Screenshot of the web app prj301-demo1 successfully
Milestone 3: Screenshot of adding image to login.html
Milestone 4: Screenshot of creating Login servlet successfully
Review the file LoginServlet.java, login.html, web.xml
Edit file web.xml to configure LoginServlet
<servlet>
<servlet-name>HomeServlet</servlet-name>
<servlet-class>com.fptuni.prj301.demo.servlet.HomeServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>LoginServlet</servlet-name>
<servlet-class>com.fptuni.prj301.demo.servlet.LoginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HomeServlet</servlet-name>
<url-pattern>/dung</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>LoginServlet</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>
Edit login.html to update the <form action=xxxx >
to call servlet.
</head>
<body>
<h1>Please login</h1>
<img src="images/header.jpg" width="200">
<form action="./login" name="" method="POST">
<input name="user" type="text">
<input name="password" type="password">
<input value="Login" type="submit">
</form>
</body>
</html>
Edit processRequest in LoginServlet to
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
/* TODO output your page here. You may use following sample code. */
out.println("<!DOCTYPE html>");
out.println("<html>");
out.println("<head>");
out.println("<title>PROJ301 Demo - Login result</title>");
out.println("</head>");
out.println("<body>");
if (request.getParameter("user").equals("dung") &&
request.getParameter("password").equals("dung") ){
out.println("correct !!!");
}else{
out.println("incorrect !!!");
}
out.println("</body>");
out.println("</html>");
}
}
Print the browser with login result and your code.
Milestone 5: Screenshot of creating Calculator servlet successfully
Follow LoginServlet above steps to make Calculator.html, CalculatorServlet
Print the browser with the result and your code.
Milestone 6: Screenshot of improving Calculator servlet successfully
Improve CalculatorServlet which shows two random numbers and enter the result
Print the browser with the result and your code.