newhtml.html
<html>
<head>
<meta http-equiv="Refresh" content="0; URL=ServletClient">
</head>
<body>
</body>
</html>
CounterServletHitsBean.java
package servlet;
import javax.ejb.Singleton;
@Singleton
public class CountServletHitsBean {
private int hitcount;
public int incrementAndGetHitCount()
{
return hitcount++;
}
}
SevletClient.java
package servlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet(name= "ServletClient", urlPatterns={"/ServletClient"})
public class ServletClient extends HttpServlet {
@EJB CountServletHitsBean CounterBean;
@Override
protected void service(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>Servlet ServletClient</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Number of times this servlet is accessed:" + CounterBean.incrementAndGetHitCount()+"</h1>");
out.println("</body>");
out.println("</html>");
}
}
}
<html>
<head>
<meta http-equiv="Refresh" content="0; URL=ServletClient">
</head>
<body>
</body>
</html>
CounterServletHitsBean.java
package servlet;
import javax.ejb.Singleton;
@Singleton
public class CountServletHitsBean {
private int hitcount;
public int incrementAndGetHitCount()
{
return hitcount++;
}
}
SevletClient.java
package servlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet(name= "ServletClient", urlPatterns={"/ServletClient"})
public class ServletClient extends HttpServlet {
@EJB CountServletHitsBean CounterBean;
@Override
protected void service(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>Servlet ServletClient</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Number of times this servlet is accessed:" + CounterBean.incrementAndGetHitCount()+"</h1>");
out.println("</body>");
out.println("</html>");
}
}
}
Comments
Post a Comment