Você está na página 1de 5

ALL ABOUT JSP

JSP -> Java Server Pages 1. JSP adalah Web dinamis / Dynamic Web Pages. To run JSP we need web server, it can be Tomcat provided by Apache. JSP can be run on any platform. 2. JSP can communicate with database and JSP is executed on web server with help of java compiler. It's saved by extension of .jsp

3. JSP is used for dynamic programming, mean we can communicate with database, insert, update, delete, alter and delete records from database with JSP. JSP code can't view at client or browser. JSP code be embedded with scriptlet <% inside JSP code %> 4. JSP is a part of Java Technology that allows web developers to create web application. Write Once, Run Anywhere: as a part of Java Technology. 5. JSP Scriptling Elements. These are the forms of scriptling elements such as: comment, expression, scriptlet, declaration and expression language. a. Comments <%-- This is a JSP comment --%> b. Expression <?= expression ?> <%= new java.util.Date()%>

c. Scriptlet <% // any java source code here %> d. Declaration <%! int x = 10; %>

6. JSP is an object-oriented programming languange based on Java.

6. The example JSP code with HTML


<%@ page language ="java" import="java.sql.*" %> <html> <head> <title>JSP Form Demo</title> <style type="text/css"> label{ margin-right:20px;} input{ margin-top:5px;} </style> </head> <body> <% String val = request.getParameter("isSubmitted"); int isSubmitted = 0; if (val != null) { isSubmitted = Integer.parseInt(val); if (isSubmitted == 1) { String firstName = request.getParameter("firstName"); String lastName = request.getParameter("lastName"); String email = request.getParameter("email"); out.println("<p>Hi " + firstName + " " + lastName + "!, your submitted email is " + email +"</p>"); } } %> <a href="coba.jsp?">Back</a> <% if (isSubmitted == 0) {%> <form action="coba.jsp" method="post"> <fieldset> <legend>User Information</legend> <label for="fistName">First Name</label> <input type="text" name="firstName" /> <br/> <label for="lastName">Last Name</label> <input type="text" name="lastName" /> <br/> <label for="email">Email</label> <input type="text" name="email" /> <br/> <input type="hidden" name="isSubmitted" value="1" /> <input type="submit" value="submit"> </fieldset> </form> <%}%> </body> </html>

Você também pode gostar