CGI
JSP and servlet came inorder to resolve drawback of CGI. CGI was first for dynamic content on web it lacks in performance as every new request creates a new process in system which comes with environment variables.
Servlet is efficient because here single process manages all requests.
JSP:-
JSP is J2ee technology for generating dynamic content. It is mixture of Java and HTML.
Advantages:-
1. Separating dynamic and static content.
Servlet : It is a J2ee technology which used for generating dynamic content. Servlet takes care of server request.
Servlet container are servlet engine which manages servlet request and response.
Request Flow is like
Request--->Servlet Container--->Servlet--->java/Bean or Database.
Example
Class OurMaximoSevlet extends HTTPServlet
{
//This is called on once to initial servlet for the first request
public void init(){
}
public void service(httpservletrequest hsr, httpserverletresponce hsrr)
throws servletexception, ioexception{
response.setContentType("text/plain");
PrintWriter out = response.getWriter();
StringBuffer html = new StringBuffer();
html.append("<html>\n");
html.append("<head><title>Servlet Example</title>" + "</head>\n");
html.append("<body>\n");
html.append("Servlet Example");
html.append("</body>");
html.append("</html>");
out.print( html.toString() );
//This method is called on every time.
}
protected void doPut(HttpServletRequest req,
HttpServletResponse resp)
throws ServletException, IOException
{
}
public void destroy(httpservletrequest hsr, httpservletresponse hsrr)
{
//used to clean the mess created by init
}
For JSP, they are converted into container before servlet run's them.
What's Get, Post and Put method
Get is ask for information without sending anything.(doget())
Post can send information with request.(dopost())
Put is sending large information and file.(doput())
Scope for Request, session and context
1. Request :- Scope is only till request ends.
2. Session :- Scope is only till session ends of user.
3. Context :- Scope is Application wide for all users.This is shared among all users.
Servlet Container :- it is that process which manages all the request.
JSP and servlet came inorder to resolve drawback of CGI. CGI was first for dynamic content on web it lacks in performance as every new request creates a new process in system which comes with environment variables.
Servlet is efficient because here single process manages all requests.
JSP:-
JSP is J2ee technology for generating dynamic content. It is mixture of Java and HTML.
Advantages:-
1. Separating dynamic and static content.
Servlet : It is a J2ee technology which used for generating dynamic content. Servlet takes care of server request.
Servlet container are servlet engine which manages servlet request and response.
Request Flow is like
Request--->Servlet Container--->Servlet--->java/Bean or Database.
Example
Class OurMaximoSevlet extends HTTPServlet
{
//This is called on once to initial servlet for the first request
public void init(){
}
public void service(httpservletrequest hsr, httpserverletresponce hsrr)
throws servletexception, ioexception{
response.setContentType("text/plain");
PrintWriter out = response.getWriter();
StringBuffer html = new StringBuffer();
html.append("<html>\n");
html.append("<head><title>Servlet Example</title>" + "</head>\n");
html.append("<body>\n");
html.append("Servlet Example");
html.append("</body>");
html.append("</html>");
out.print( html.toString() );
//This method is called on every time.
}
public void doget(httpservletrequest hsr, httpserverletresponce hsrr)
throws servletexception, ioexception{
//called only when service method is not present
}
public void dopost(httpservletrequest hsr, httpserverletresponce hsrr)
throws servletexception, ioexception{
//called only when service method is not present
}
protected void doPut(HttpServletRequest req,
HttpServletResponse resp)
throws ServletException, IOException
{
}
public void destroy(httpservletrequest hsr, httpservletresponse hsrr)
{
//used to clean the mess created by init
}
For JSP, they are converted into container before servlet run's them.
What's Get, Post and Put method
Get is ask for information without sending anything.(doget())
Post can send information with request.(dopost())
Put is sending large information and file.(doput())
Scope for Request, session and context
1. Request :- Scope is only till request ends.
2. Session :- Scope is only till session ends of user.
3. Context :- Scope is Application wide for all users.This is shared among all users.
Servlet Container :- it is that process which manages all the request.
Comments
Post a Comment