Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Jsp (java server page)


Published on

This is a brief presentation on Java Servlets and JSP.

Published in: Education, Technology
  • Be the first to comment

  • Be the first to like this

Jsp (java server page)

  1. 1. Introduction
  2. 2. History of Server side scripting JavaCGI-Perl JSP Servlets
  3. 3. CGI (common gateway interface)1. Scripts are linked and executed on the web server.2. CGI includes Perl, C++, Visual Basic and even java.3. biggest disadvantage to using CGI was that it placed a tremendous load on your Web server as it is executed on the web server
  4. 4. Java Servlets Platform Independence Performance Extensibility Safety Secure
  5. 5. Types of servlet• Generic Servlet Class (Inherit)• HttpServlet Class(Inherit)• Servlet interface (Implement)
  6. 6. HttpServlet Web Request componentsWebClient JavaBeans HttpServlet Components Response
  7. 7. Life cycle of ServletImport*;Import javax.servlet.*;Import javax.servlet.http.*;Public class TestServlet extends HttpServlet{ public void init() // called only once at start {
  8. 8. /* It can be used for those elements which always need an initialization like JDBC but it is optional to use */}Public void service/doGet/doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException , IOException{ /* Common method used for initializing JDBC ,server based operations and redirect to pages. */
  9. 9. Public void destroy() //terminates the servlet{ /* rarely used*/}}
  10. 10. JSP(Java Server Page)• Addressing jsp page is simpler than servlets.• Servlet goes with two pages hand in hand like for logging login.html (used as an index) (used for request and response).• Only one page enough login.jsp . JSP provides better compatibility with web development tools.
  11. 11. Difference in codeJava Servlets JSPClass …. <html>{ …… …. <% out.print(“welcome user”); out.write(“Login page”); out.print(“<body>”); %> ……… </html>}
  12. 12. What is JSP ?Template for a web page that uses java code to generate HTML documents dynamically. JSP runs in a server side component known as JSP container.JSP Container translates them into equivalent java code. JSP is similar to ASP and PHP, but it uses the Java programming language.
  13. 13. JSP Fundamentals• <% ….. %> Scriptlets• <%! … %> Declarative• <%@...%> Directive• <%= … %> Expressions
  14. 14. Jsp program• File name index.jsp<%@ … %><html><body><form name=“f1” action=“Check.jsp”>Name :- <input type=“text” name=“name” /><input type=“submit” name=“submit” value=“submit”/>
  15. 15. </form></body></html>
  16. 16. • Check.jsp<%@. %><html><body><% String nm=request.getParameter(“name”);%><table><tr> <td> <% out.write(nm)%> </td></tr>
  17. 17. </table></body></html>
  18. 18. MVC Model Database Model AccessPresentation DBData Model Updates User Input View Next View Controller Delegate State actions Actions