7. How code works
<%--
Document : newjsp
Created on : Sep 14, 2015, 8:47:33 AM
Author : B N Kshirsagar
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%@page import="java.util.*" %>
<h1>Hello World!</h1>
<br>
The time is now <%= new Date() %>
${1+3}
</body>
</html>
10. Code : systemproperties.jsp
<body>
<h1>Your Computer System Properties</h1>
<br>
Java version is <%= System.getProperty("java.version") %>
<hr>
OS is <%= System.getProperty("os.name") %>
<hr>
Java Home is <%= System.getProperty("java.home") %>
<hr>
User name is <%= System.getProperty("user.name") %>
<hr>
User Home is <%= System.getProperty("user.home") %>
<hr>
User dir is <%= System.getProperty("user.dir") %>
</body>
13. Code : scriptletdate.jsp
<body>
<%@page import="java.util.*" %>
<%
// This is a scriptlet. Notice that the "date"
// variable we declare here is available in the
// embedded expression later on.
System.out.println( "Evaluating date now" );
java.util.Date date = new Date();
int a = 10;
int b = 20;
int c = a + b;
%>
Hello! The time is now <%= date %>
<hr>
The value of a <%= a %>
<hr>
The value of b <%= b %>
<hr>
The value of sum of and b i.e. c <%= c %>
<hr>
19. Code : scriptlethello.jsp
<%--
Document : scriptlethello.jsp
Created on : Oct 2, 2015, 10:16:48 AM
Author : B N Kshirsagar
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%
out.println("<HTML>");
out.println("<Title> This is scriptlet</Title>");
out.println("<Body>");
out.println("Hello! The time is now ...");
out.println("</Body>");
out.println("</HTML>");
%>
24. Code : directives.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Directive Page</title>
</head>
<body>
<h1>Directives !</h1>
<%@ page import="java.util.*" %>
<%
System.out.println( "Evaluating date now" );
Date date = new Date();
%>
Hello! The time is now <%= date %>
</body>
</html>
26. Code : directiveinclude.jsp
<body>
<h1>Include Directive page !</h1>
<h2>This program uses JSP include directive ,
it includes file systemproperties.jsp </h2> <br>
Going to include systemproperties.jsp...<BR>
<%@ include file="systemproperties.jsp" %>
</body>
28. Code : declaration.jsp
<body>
<h1>JSP Declarations !</h1>
<%@ page import="java.util.*" %>
<%!
Date theDate = new Date();
Date getDate()
{
System.out.println( "In getDate() method" );
return theDate;
}
Date computeDate()
{
System.out.println("Re-Initializing date " );
theDate = new Date();
return theDate;
}
%>
<%--
Hello! The time is now <%= getDate() %>
--%>
Hello ! New time is <%= computeDate() %>
46. Bean : UserData.javapackage user;
public class UserData {
String username;
String email;
int age;
public void setUsername( String value )
{
username = value;
}
public void setEmail( String value )
{
email = value;
}
public void setAge( int value )
{
age = value;
}
public String getUsername() { return username; }
public String getEmail() { return email; }
public int getAge() { return age; }
}
55. Thank you
Contact:
Prof Rahul Mapari
MIT- Oracle Workforce Development Program
Department of Computer Science & Engineering
G.S.Mandal’s Maharashtra Institute of Technology, Aurangabad, MS, INDIA