Java Video Tutorial 43

Java Server Pages Video TutorialHere is part 1 of my Java Server Pages video tutorial. To completely understand everything you need to see my Java Servlet Video Tutorial.

Unlike Java Servlets a JSP file allows you to easily co-mingle HTML, JavaScript and Java code all in one file. You do that by placing different types of Java code in special brackets.

It sounds harder than it is and after this video you’ll be writing your own JSPs. The code follows the video to help you learn.

If you like videos like this, tell Google [googleplusone]

Always feel free to share

Code From the Video

<!-- A Java Server Page is an html file with Java embedded using tags -->
<!-- This is a JSP Directive that sets options and imports libraries -->

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">

<!-- Another JSP Directive -->

<%@ page import="java.lang.Math.*" %>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>

<!-- This is a Scriptlet Java code inserted in the html -->
<!-- You can enter any core Java code between these tags -->

<% out.print("Todays Date: "); %>

<!-- This is an Expression code that evaluates to a String -->

<%=new java.util.Date() %>

<!-- You can create fields and methods in Declarations -->

<%! int number1, number2; %>
<br /><br />

<!-- I create a form that will talk to this page -->

<form action="calculatejsp.jsp" method="post">

Enter 2 Numbers:
<input type="text" name="numone" />

<input type="text" name="numtwo" />

<input type="submit" value="Calculate" />


The Answer:

<!-- JSP expression code that prints the values of the fields -->

<%= request.getParameter("numone") %>
<%= request.getParameter("numtwo") %>

<!-- Another Scriplet block of code -->

// Grab the value of numone & numtwo and convert them to ints

number1 = Integer.parseInt(request.getParameter("numone"));
number2 = Integer.parseInt(request.getParameter("numtwo"));
int sumOfNums = number1 + number2;
out.print(" = " + sumOfNums); 
catch (NumberFormatException ex)
  // do something with the exception


5 Responses to “Java Video Tutorial 43”

  1. mr.roshik says:

    I’ve a question out of this topic. Please don’t mind. Suppose i’ve made a static web site and i wanna hide my html, css code. is it possible? If yes then how is it possible? Please share.

  2. Punit says:

    hey darek.
    nice video, but when you are making videos for EL, JSTL, custom tags and all, because now a days scriptlet’s are obsolete.

Leave a Reply

Your email address will not be published.