100 likes | 121 Views
Introduction to JSP. Yingcai Xiao. JSP. JavaServer Page Server side programming language Java imbedded in HTML Compiled Object-oriented Similar to ASP.NET Dynamically generates web pages. JSP Example. <html> <head> <title> Get a Celsius temperature </title> </head> <body>
E N D
Introduction to JSP Yingcai Xiao
JSP • JavaServer Page • Server side programming language • Java imbedded in HTML • Compiled • Object-oriented • Similar to ASP.NET • Dynamically generates web pages .
JSP Example <html> <head> <title> Get a Celsius temperature </title> </head> <body> <!-- Display a form to collect a Celsius temperature --> <form action = "tempconvert0.jsp" method = "get" > Celsius temperature: <input type = "text" name = "ctemp" /> <input type = "submit" /> </form> </body> </html> .
JSP Example <html> <head> <title> Temperature converter </title> </head> <body> <% // Get the Celsius temperature from the form String strCtemp = request.getParameter("ctemp"); float ftemp; // convert the value to Fahrenheit ftemp = 1.8f * Integer.parseInt(strCtemp) + 32.0f; %> <!-- Use an expression to display the value of the Fahrenheit temperature --> Fahrenheit temperature: <%= ftemp %> </body> </html> .
JSP Programming • Three ways of imbedding code in HTML: external, document, inline. • Imbedding tags: CSS: <style></style> JS: <script></script> PHP: <?php?> JSP: <%> .
JSP Programming • 5 steps of Web-based server-side computation: • Get input as text from client. • Convert text to numbers. • Compute. • Convert numbers to text. • Sent output to client • In the example, step 4 is done automatically by type conversion. • Step 5 is just “=“. .
JSP References • https://en.wikipedia.org/wiki/JavaServer_Pages • http://www.oracle.com/technetwork/java/javaee/jsp/index.html • http://docs.oracle.com/javaee/5/tutorial/doc/bnagx.html • https://www.tutorialspoint.com/jsp/ .
JSP Interview Questions • https://www.tutorialspoint.com/questions_and_answers.htm .
JSP vs Servlet • Java Servlets are server side Java programs. • Pure java code, not embedded. • Object oriented • Compiled • Runs faster than JSP • JSP usually used to created UI. • Servlets usually are used to create backend code. .
JDBC • Java Database Connectivity • https://en.wikipedia.org/wiki/Java_Database_Connectivity • http://www.oracle.com/technetwork/java/javase/jdbc/index.html • https://docs.oracle.com/javase/tutorial/jdbc/basics/