examples

Getting Started With Java Server Pages (JSPs) Lab

JSPs allow you to write html, css, javascript etc. just as if you were writing an html file.  JSPs can be considered as html pages (except for the .jsp extension and some extra lines) with some java code inside.  JSPs may also contain no Java at all. In this example we will create our first JSP page, deploy it on Apache Tomcat and then runt it.

 

Prerequisites

  • JDK (1.7 or more)

  • Eclipse IDE (Mars or more)

[Demo] Simple Servlet Filter and Servlet FilterChain

Filters are pluggable classes that stand between the client and a target component (like a servlet or JSP), within a web application. We can do pre or post processing of request/response data while it is coming from client to a servlet or from the servlet back to a client. 

Create a Servlet TargetServlet with URL Pattern as “/TargetServlet” and print some content to console from its doGet method. Code for TargetServlet is given in the end.

Now create a filter that will have the same url pattern for the servlet.

[Demo] RequestDispatcher Mechanism in Servlet

RequestDispatcher mechanism used for forwarding to and including other resources. We will understand the basics of RequestDispatcher mechanism using a simple exercise.

Before proceeding, you need to configure your eclipse and tomcat. I am using eclipse Eclipse Java EE IDE for Web Developers version: Luna and Apache Tomcat version 8.0.18. Apache Tomcat version 8.0.18 support Servlet Spec 3.1, JSP Spec 2.3, EL Spec 3.0, WebSocket spec 1.1 and support java version 7 and above.

 

Getting Started with Gradle in Windows OS - Hello World Build

We will download, install and configure gradle, and then execute a simple program.

 

Prerequisites

  1. Gradle 1.x requires a Java JDK 5 or higher to be installed and the location needs to be added to an environment variable JAVA_HOME. 

  2. Gradle 2.x requires a Java JDK 6 or higher to be installed and the location needs to be added to an environment variable JAVA_HOME. 

JavaFX HelloWorld Command line Program without Eclipse Plugin & Scene builder

We will write a simple JavaFX application that displays a “Hello World” button. We will handle any button click events to print “Hello World” in the console. The program can be run from command line or from an IDE like eclipse, but without the Eclipse Plugin for JavaFX and Scene builder.

 

Packaging and Deploying a Web Application into Standalone Apache Tomcat

You need to package your web application as a .war file to deploy it directly to Apache Tomcat. WAR stands for web archive. A different server might require a different format, for instance a glassfish server will need a .jar file whereas a websphere application server will require an .ear.

 

Installing and verifying a standalone Apache Tomcat

We will use a stand-alone tomcat for this example. Just download latest tomcat (.zip) version, unzip into a folder.

Hello World JSP Web Application in Eclipse with Tomcat

We will create a simple JSP that prints "Hello World" in eclipse, deploy it and run it on the integrated tomcat. 

 

Prerequesites

Configure apache tomcat with eclipse as mentioned in configuring-apache-tomcat-with-eclipse and start and stop tomcat server from the servers view of eclipse.

 

Hello World Servlet Application in Eclipse With Tomcat

We will create a simple servlet that prints "Hello World" in eclipse, deploy it and run it on the integrated tomcat. 

 

Prerequesites

Configure apache tomcat with eclipse as mentioned in configuring-apache-tomcat-with-eclipse and start and stop tomcat server from the servers view of eclipse.

 

[Example-Lab] Hands On Exercise and Quiz on Exceptions

Let us do a simple hands on excercise followed by some questions to understand exceptions better. For theory and concetps of exceptions in Java. you can refer to the note introduction-to-exceptions-in-java

 

Exercise

Create a class MyClass and create three methods myMethod1(), Method2() and Method3().

 

Invoke Method2() from Method1() and Method3() from Method2().

JSP Web Application With Form Submission Lab

We will create a simple JSP form and then submit the form with action as another jsp and retrieve the form parameters which are received as request parameters in the second jsp file.

 

Create a 'Dynamic Web Project'.

  • Select 'File > New > Dynamic Web Project' or  'File > New > Project > Web > Dynamic Web Project'.  

Pages

Search the Web

Custom Search

Searches whole web. Use the search in the right sidebar to search only within javajee.com!!!